How can I store and retrieve Unicode or Double Byte data in a file using the java.io libraries?
Location: http://www.jguru.com/faq/view.jsp?EID=70736 Created: Jun 9, 2000 Modified: 2001-08-18 17:27:31.039 Author: Joe Sam Shirah (http://www.jguru.com/guru/viewbio.jsp?EID=42100) Question originally posed by Tian Hao (http://www.jguru.com/guru/viewbio.jsp?EID=56209 Java supports a number of encodings for use with InputStreamReaders and OutputStreamWriters. By using these classes, it’s easy to read and write Unicode or any other supported encodings. Here’s some code that writes a Unicode string to a file and then reads it back in. Please note that the sample’s emphasis is on Unicode functionality — obviously more care should be taken with exceptions and file closings in a production program: import java.io.*; public class WRUni { public static void main(String[] args) { FileOutputStream fos = null; OutputStreamWriter osw = null; BufferedWriter bw = null; FileInputStream fis = null; InputStreamReader isr = null; BufferedReader br = null; String sUni = null; try { // write a UniCode s