Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading and Writing Chinese Characters from file  RSS feed

 
Sakuragi Hanamichi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I need help on reading and writing of Chinese characters encoded as UTF-8(but they are not in the u\xxxx) format. If you open it in Notpad, you will be able to view the chinese writings in it.
What I need to do is read thru the file(saving the data in ArrayLists and VO's) and rewrite it down to a new file. The problem is after I read the file, do the operations and write the file to disk, I'm not able to view the characters as chinese anymore. Please help... I really need this.

Thanks.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I need to do is read thru the file(saving the data in ArrayLists and VO's) and rewrite it down to a new file.

Is your goal just to rewrite the data to a new file, or are you doing some other processing too? That is, do you need to save the data in an ArrayList for some reason?

If you just need to transfer from file to file, I recommend using FileInputStream and FileOutputStream only. Just write the raw bytes from one stream to the other. Or use FileChannel's transferTo() method.

But if you need to do some other processing which requires you to convert the data to Strings, then I'd do something like this:

In order to convert bytes in a file to chars or Strings, you need the InputStreamReader and OutputStreamWriter to correctly specify the encoding to be used. (Unless you're using JDK 1.5, which has some enhancements to FileReader and FileWriter which will help you.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!