Cách xử lý file trong Java
-----------
Ví dụ minh họa
package fileProcess1;
import java.io.*;
class fileProcess {
void writeToFile() throws IOException {
File fo = new File("D:\\data.txt");
FileWriter fw = new FileWriter(fo);
try {
fw.write("Hello World");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
fw.close();
}
void readFromFile() throws IOException {
File fi = new File("D:\\data.txt");
FileReader fr = new FileReader(fi);
BufferedReader br = new BufferedReader(fr);
String str;
try {
while ((str = br.readLine()) != null) {
System.out.println(str);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
br.close();
fr.close();
}
}
public class demo {
public static void main(String[] args) throws IOException {
fileProcess f = new fileProcess();
f.writeToFile();
f.readFromFile();
}
}
Trương Đình Huy
- So sánh giữa tiếng Anh của thập niên 90 và tiếng Anh của giới trẻ hiện nay
- GNN: Khi AI “hiểu” được mối quan hệ, không chỉ là dữ liệu
- XU HƯỚNG CONTENT MARKETING HIỆN NAY: SỰ CHUYỂN DỊCH TỪ NỘI DUNG ĐẾN TRẢI NGHIỆM
- Sự kiện đối thoại ART.ITECTURE #2: Xây dựng cảm xúc - Cách âm nhạc và kiến trúc định hình trải nghiệm của con người
- Các khía cạnh đạo đức trong quảng cáo

