如这个文件

【java】之读取InputStream流_System

 

@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);
    }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

 

读取结果

 

【java】之读取InputStream流_Test_02