Sunday, 24 April 2016

How to write UTF-8 encoded data into a file ?


Use OutputStreamWriter with UTF-8 parameter

Example
File fileDir = new File("c:\\temp\\test.txt");
Writer out = new BufferedWriter(new OutputStreamWriter(
                   new FileOutputStream(fileDir), "UTF8"));

out.append("Website UTF-8").append("\r\n");
out.append("?? UTF-8").append("\r\n");
out.append("??????? UTF-8").append("\r\n");

out.flush();

out.close();

No comments:

Post a Comment

Note: only a member of this blog may post a comment.