May 6, 2010

Write file encode UTF-8 in java

Here is example code:

FileOutputStream fileOutputStream = new FileOutputStream( "filename.csv");
byte[] bom = new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
fileOutputStream.write(bom);
PrintWriter out = new PrintWriter(new OutputStreamWriter(fileOutputStream, "UTF-8"));

out.write("text");


if(out != null){
out.flush();
out.close();
}

0 Comment:

Post a Comment

Để chất lượng các bài viết ngày được tốt hơn, Bạn vui lòng để lại góp ý hoặc nhận xét vào khung bên dưới. Bạn có thể tự do nhận xét nhưng không trái với thuần phong mỹ tục. Khi gửi nhận xét xin vui lòng để lại: Tên, Địa chỉ mail hoặc địa chỉ Blog để tôi được biết bạn là ai. Xin cảm ơn!

Các bài liên quan




Recent Comments

Xã hội - VnExpress.net