使用read()方法取一个字节数据
package Reading;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/* 读取文件中的数据,使用read方法
*/
public class Reading { public static void main(String[] args) { FileInputStream fos = null; try { fos = new FileInputStream("fors.txt"); } catch (FileNotFoundException e) { e.printStackTrace(); } try { int by; while((by = fos.read())!=-1){ System.out.print((char)by); } } catch (IOException e) { e.printStackTrace(); } try { fos.close(); } catch (IOException e) { e.printStackTrace(); } }
}