【java】之读取InputStream流

 如这个文件

    @Test
    public void test01() throws Exception{
        InputStream in=new FileInputStream("c://test.txt");
        byte[] b=new byte[1024];
        ByteArrayOutputStream  out=new ByteArrayOutputStream();
        int len=-1;
        while((len=in.read(b))!=-1){
            out.write(b,0,len);
        }
        out.close();
        in.close();
        String str= new String(out.toByteArray(),"UTF-8");
        System.out.println(str);
    }

读取结果

原文地址:https://www.cnblogs.com/gyjx2016/p/6068247.html