wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Problem while Reading Japanese Characters from a Text File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem while Reading Japanese Characters from a Text File" Watch "Problem while Reading Japanese Characters from a Text File" New topic
Author

Problem while Reading Japanese Characters from a Text File

Souvik Das
Greenhorn

Joined: Oct 11, 2007
Posts: 15
Hi,
I have a text file where the text is written in Japanese. While I want to read the file using Java it can not recognise the japanese characters and it is giving "???" like characters instead of Japanese characters.

FileInputStream fis = new FileInputStream("out.txt");
InputStreamReader isr = new InputStreamReader(fis,"UTF-8");

Reader in = new BufferedReader(isr);

StringBuffer buf = new StringBuffer();
int ch;
while ((ch = in.read()) > -1) {
buf.append((char)ch);
}
in.close();

String message = new String(buf.toString()); // Here i want the japanese characters to appear
System.out.println(message);

I want to save the contents of the text file in a string.
I have also tried "Shift_Jis" encoding isnstead of "UTF-8" encoding also but those did not help me much.

Thanks in advance.
Regards,
Souvik
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
You are printing this on the console.

For the OS to interpret this characters and display correctly; you need to set the OS encoding accordingly.

The fact that it is displaying ??? means that the OS is not able to find the relevant code page(encoding) and it is trying to use the default encoding to interpret the stream.

Instead of console output, write it to a file and open this file in browser and check if the characters are displayed correctly.


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem while Reading Japanese Characters from a Text File
 
Similar Threads
How can I get Unicode String of a String?
readUTF not working
file, UTF8
Setting strings explicitly and using JOptionPane - UTF Character conversion problems...
Reading Japanese Characters from Text File