集册 Java实例教程 将InputStream转换为String

将InputStream转换为String

欢马劈雪     最近更新时间:2020-01-02 10:19:05

555
将InputStream转换为String


import java.io.BufferedReader;/** 来自 时 代 J     a    v  a - nowjava.com**/

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.Scanner;

 

public class Main {

       

        public static void main(String args[]) throws IOException{

                InputStream is = new FileInputStream("c:/data.txt");

                String strContent;

               

                //Create BufferedReader object

                BufferedReader bReader = new BufferedReader(new InputStreamReader(is));
                /*
                来 自*
                 nowjava.com - 时代Java
                */

                StringBuffer sbfFileContents = new StringBuffer();

                String line = null;

               

                //read file line by line

                while( (line = bReader
展开阅读全文