Java中,IO流(三):字元流的過濾器
阿新 • • 發佈:2019-02-10
import java.io.*; /** *字元流的過濾器 BufferedReader ---->readLine 一次讀一行 BufferedWriter/PrintWriter ---->寫一行 */ public class BrAndBwOrPwDemo { public static void main(String[] args) throws IOException { //對檔案進行讀寫操作 BufferedReader br = new BufferedReader( new InputStreamReader( newFileInputStream("C:\\Users\\hasee\\Desktop\\demo\\字元流3.txt"),"GBK")); /*BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( new FileOutputStream("C:\Users\hasee\Desktop\demo\字元流4.txt"),"GBK"));*/ PrintWriter pw = new PrintWriter("C:\\Users\\hasee\\Desktop\\demo\\字元流4.txt"); //PrintWriter pw1 = new PrintWriter(outputStream,boolean autoFlush); String line ; while((line = br.readLine())!=null){ System.out.println(line);//一次讀一行,並不能識別換行 /*bw.write(line); //單獨寫出換行操作 bw.newLine();//換行操作 bw.flush();*/ pw.println(line); pw.flush();} br.close(); //bw.close(); pw.close(); } }