我想我需要使用如何写文件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);“? –