Here's the Java example to demonstrate what to write UTF-8 encoded data into a text file– "C:\\temp\\test.txt" P.S Symbol " ?? ' is some ' utf-8″data in Chinese and japanesepackage Com.mkyong; Import Java.io.bufferedwriter;import java.io.file;import java.io.fileoutputstream;import java.io.IOException; Import Java.io.outputstreamwriter;import Java.io.unsupportedencodingexception;import java.io.Writer; public class Test {public static void main (string[] args) {try {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 (); } catch (Unsupportedencodingexception e) {System.out.println (E.getmessage ()); } catch (IOException e) {System.out.println (E.getmessage ()); } catch (Exception e) {System.out.println (E.getmessage ()); } }}
How to write UTF-8 encoded data into a File–java