java read n write to file with unicode text
i write a code to read a file with text written in utf-8 and write in another file...but always it write whole text in ?????????
import java.io.*;
import java.nio.charset.Charset;
class Readnwrite {
public static void main(String args[]) throws Exception {
Charset ch = Charset.forName("UTF-8");
BufferedReader bufReader = new BufferedReader(new InputStreamReader(new FileInputStream("abc.txt"),ch));
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
String s;
while((s = bufReader.readLine()) != null) {
out.write(s);
System.out.println(s);
}
out.close();
}
}
What is the problem ....................
Re: java read n write to file with unicode text
Does the Sys.out print the correct text?
How are you checking the file?
What does the original file contain?
If you aren't concerned with actually using the stuff read in then just read and write bytes using an InputStream and an OutputStream, that way you can ignore the character set entirely.