925-3

package lesson0925;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Third {

public static void main(String[] args) throws IOException {
	FileOutputStream fos = new FileOutputStream("春晓.txt");
	PrintWriter pw = new PrintWriter(fos);
	Scanner scan = new Scanner(System.in);
	int i = 1;
	while(true) {
		System.out.println("请输入第"+i+"句");
		String line = scan.next();
		if("exit".equals(line)) {
			break;
		}
		pw.println(line);
		i++;
	}
	pw.close();
	//读取文件内容
	FileReader fr = new FileReader("春晓.txt");
	BufferedReader br = new BufferedReader(fr);
	String line = null;
	while((line=br.readLine())!=null) {
		System.out.println(line);
	}
	br.close();
}

}

你可能感兴趣的:(925-3)