• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem while Reading Japanese Characters from a Text File

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic