天天看點

将鍵盤錄入的資料,通過列印流(PrintWriter)寫入本項目下的aa.txt中

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.CharBuffer;

public class Work01 {

	@SuppressWarnings("resource")
	public static void main(String[] args) throws Exception {
//	将鍵盤錄入的資料,通過列印流(PrintWriter)寫入本項目下的aa.txt中
//		method01();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter("aa.txt");
		String len;
		while((len=br.readLine())!=null){
			pw.println(len);
			pw.flush();
		}
		br.close();
		pw.close();
		

	}

	private static void method01() throws FileNotFoundException, IOException {
		InputStreamReader in = new InputStreamReader(System.in);
		
		PrintWriter pw = new PrintWriter("aa.txt");
		int  a;
		char[] ch=new char[1024];
		
		while((a=in.read(ch))!=-1){
			pw.println(new String(ch));
			pw.flush();
		}
		pw.close();
		in.close();
	}

}
           

繼續閱讀