I am trying to read file using Java and the file also containing special characters also. I am trying to write the contents of file into another file.
What is the so
You need to find out the exact encoding that the file uses, and then specify that in the
InputStreamReader
parameter.
Nevertheless it is often best to reader character data by wrapping your InputStream with an InputStreamReader into Reader or BufferedReader
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(your file), "UTF-8"));
Edit For Comment:
FileReader
uses Java's platform default encoding, which depends on the system settings of the computer on which its running on.
Unfortunately
FileReader
does not allow to set encoding. Instead, you have to use Above code to get the desire encoding for your file.
Encode file in UTF-8 and use java encoding aware streams operators:
new InputStreamReader(new FileInputStream(file), "UTF-8")