aspose file tools*
The moose likes I/O and Streams and the fly likes How do I read and write text files with different character sets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How do I read and write text files with different character sets?" Watch "How do I read and write text files with different character sets?" New topic
Author

How do I read and write text files with different character sets?

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 688

I need to be able to read and write text files to and from the following character sets: ASCII, ISO-8809-1, MacRoman, and UTF-8.

I have developed the following code which works, but I don't know how to specify the character set.

Will somebody tell me how to modify my code so that the Charset object that is used can be a parameter?




[ September 10, 2008: Message edited by: Kaydell Leavitt ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39537
    
  27
Instead of FileReader -> BufferedReader you'd use FileInputStream -> InputStreamReader -> BufferedReader. The InputStreamReader constructor can take a CharSet as a parameter. It works similarly for output streams instead of a Writer.


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I read and write text files with different character sets?
 
Similar Threads
File IO with Servlet
spaces in String
fileREader and FileWriter
Copying MS Access Database
Reading from file A, writing to file B