package com.io.test;import java.io.FileInputStream;
import java.io.FileOutputStream;public class BytesStreamTest
{ private static int BUFFER_SIZE = 1024; public static void main(String[] args) throws Exception
{
readTest();
}
//此方法抛异常——如何解决?
public static void readTest() throws Exception
{
FileInputStream fis = new FileInputStream("output.txt"); byte[] buf = new byte[BUFFER_SIZE];
int ch = 0;
while((ch = fis.read()) != 0)
{
System.out.println(new String(buf,0,ch));
} fis.close();
}
}
FileInputStream fis = new FileInputStream("output.txt"); byte[] buf = new byte[1024];
int ch = 0;
if( 0 != (ch = fis.read(buf))){
System.out.println(new String(buf, 0, ch));
} fis.close();
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;public class BytesStreamTest
{ private static int BUFFER_SIZE = 1024; public static void main(String[] args) throws Exception
{
readTest();
}
public static void readTest() throws Exception
{
FileInputStream fis = new FileInputStream("output.txt");
byte[] buf = new byte[BUFFER_SIZE];
int ch = 0;
while((ch = fis.read(buf)) != -1)
{
System.out.println(new String(buf,0,ch));
} fis.close();
}
}