Java IO簡要方法總結

鴨脖發表於2012-04-22
對控制檯的讀寫
讀:
BufferedReader stdIn = new  BufferedReader(new  InputStreamReader(System.in));
寫:
PrintWriter  stdOut = new  PrintWriter(System.out, true);
寫:
PrintWriter  stdErr = new  PrintWriter(System.err, true);


對檔案的讀寫
讀:
BufferedReader stdIn = new BufferedReader(new FileReader("a.txt"));
使用read()方法讀取單個字元,使用readLine()方法讀取一個文字行
寫:
PrintWriter stdOut = new PrintWriter(new FileWriter("b.txt"));
append方式寫:
PrintWriter stdOut = new PrintWriter(new FileWriter("b.txt",true));

相關文章