IO練習(FileReader和Writer對檔案進行讀寫)
阿新 • • 發佈:2018-12-16
package aa; import java.io.*;
public class aaa { public static void main(String[] args) throws IOException { File file=new File("F://file.txt"); FileWriter s=new FileWriter(file); BufferedWriter s1=new BufferedWriter(s) ; String []str1= {"星期一","星期二","星期三","星期四","星期五","星期六","星期天"}; for(String a:str1) { s1.write(a); s1.newLine(); } s1.close(); FileReader r1=new FileReader(file); BufferedReader s2=new BufferedReader(r1); String str=s2.readLine(); while(str!=null) { System.out.println(str); str=s2.readLine(); } s2.close(); } }