我想我需要使用如何寫文件UTF8?
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "UTF8"));
但是,當我在我的代碼更改的BufferedWriter,那麼什麼是錯與線out.write(e);
。
我的代碼:
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();
}
}
它顯示了文件:
//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$
什麼,我想讓它顯示的是:
//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$
我怎麼能寫UTF-8文件並將「3」更改爲「03」?
是的,你需要使用BufferedWriter。 – Kayaman
這是可能的重複http://stackoverflow.com/questions/1001540/how-to-write-a-utf-8-file-with-java/1001562#1001562 –
你是什麼意思「然後有些事情是錯的與線out.write(e);「? –