package rw; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; public class test { public static void main(String[] agrc) throws IOException { //写入文件 FileOutputStream out = new FileOutputStream("test.txt"); for(int i=0;i<100;i++) { String s = "this line is " + i+" "; out.write(s.getBytes()); } out.close(); //读取文件 FileInputStream in = new FileInputStream("test.txt"); // 读取文件路径 BufferedReader br = new BufferedReader(new InputStreamReader(in)); for(int i=0;i<100;i++) { String line = br.readLine(); System.out.println(line); } br.close(); in.close(); } }