File file = new File("1.txt");
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String text = reader.readLine();
String s1="\u6df1\u6c34\u57d7";
String s2="深水埗";
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream("2.txt"),"UTF-8");
out.write(text+s1+s2);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
Sunday, March 27, 2011
Reading and saving UTF8 text file in Java
To read and save text file in Java, we need to add the "UTF-8" parameter in the Stream Reader.
Subscribe to:
Posts (Atom)
Sync multiple git repo at once
Use the following command in Linux will do the job: ls -d RepoNames* | xargs -I{} git -C {} pull
-
When Office2003 couldn't find file SKU011.CAB: regedit -> [HKEY_LOCAL_MACHINE] -> [SOFTWARE] -> [Microsoft] -> [Office] -&...
-
The resolution can be changed by editing the BlueStack's registry: HKLM\SOFTWARE\BlueStacks\Guests\Android\FrameBuffer\0\Height and ...
-
To count the number lines of files / stdout in Linux, we uses "wc -l" to achieve. In Windows, we use the following instead: find...