Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Reading and Writing Chinese Characters from file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic