I think I need to use
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "UTF8"));
But when I change my code to BufferedWriter, then something is wrong with the line out.write(e);
.
My code:
public void writeToFile(String fileName, List<ThongtinKhachThue> resultttkt){
System.out.println("Begin....");
try {
PrintWriter out = new PrintWriter(new File(fileName));
out.println("//thue.txt");
for(ThongtinKhachThue e : resultttkt){
out.println(e);
}
out.println("Tổng khách thuê phòng: "+TongKhachThue());
out.println("Tổng tiền thu: "+TongTienThuDuoc()+"$");
out.flush();
out.close();
System.out.println("End...");
} catch (FileNotFoundException e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}
what it shows in file:
//thue.txt
K1, A1002, 47.05$
K2, A0003, 67.0$
K3, A1001, 31.0$
K4, null, 0.0$
T?ng khách thuê ph?ng: 3
T?ng ti?n thu: 145.05$
what I want it to show is:
//thue.txt
K1, A1002, 47.05$
K2, A0003, 67.0$
K3, A1001, 31.0$
K4, Không thuê
Tổng khách thuê: 03
Tổng tiền thu: 145.05$
How can i write utf-8 to file and change "3" to "03"?