Skip to main content

Posts

Showing posts with the label UTF-8

How to Read and Write UTF-8 File in Java?

-- The InputStreamReader and the OutputStreamWriter support UTF-8 character encoding. Here is example code: public class Program { public static void main(String... args) { if (args.length != 2) { return ; } try { Reader reader = new InputStreamReader( new FileInputStream(args[0]),"UTF-8"); BufferedReader fin = new BufferedReader(reader); Writer writer = new OutputStreamWriter( new FileOutputStream(args[1]), "UTF-8"); BufferedWriter fout = new BufferedWriter(writer); String s; while ((s=fin.readLine())!=null) { fout.write(s); fout.newLine(); }