129.(位元組流、字元流)對檔案進行讀寫操作

Away_D發表於2017-08-03

public class Main{

public static void main(String[] args) throws Exception{

String value="中國風\n";

String value2="a 中國風\n";

PrintWriter pw=new PrintWriter("temp.txt","UTF-8");

pw.write(value);

pw.write(value2);

pw.close();

// 從檔案中讀取內容

/*

FileInputStream fis=new FileInputStream("temp.txt");

InputStreamReader isr=new InputStreamReader(fis,"utf-8");

BufferedReader br=new BufferedReader(isr);

String b;

while((b=br.readLine())!=null){

System.out.println(b);

}

br.close();

*/

BufferedReader bfr=new BufferedReader(new InputStreamReader(new FileInputStream("temp.txt"),"utf-8"));

String b;

while((b=bfr.readLine())!=null)

System.out.println(b);

bfr.close();

}

}



FileInputStream

InputStreamReader

BufferedReader

br.readLine();

相關文章