Minh họa cấu trúc lệnh xử lý file trong Ngôn ngữ lập trình Java
package fileProcess4;
import java.io.*;
public class demo {
private static BufferedReader br;
public static void main(String[] args) throws IOException {
File f = new File("D:\\test1.txt");
FileWriter fw = null;
try{
fw = new FileWriter(f);
fw.write("Truong Dinh Huy\n");
fw.write("Khoa DTQT");
System.out.println("OK!");
}catch(IOException e){
e.printStackTrace();
}
finally{
fw.close();
}
BufferedReader br = null;
try{
FileReader fr = new FileReader("D:\\test1.txt");
br = new BufferedReader(fr);
String s;
while((s = br.readLine()) !=null){
System.out.println(s);
}
}catch(IOException e){
e.printStackTrace();
}
br.close();
}
}
Trương Đình Huy
» Tin mới nhất:
» Các tin khác: