This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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: 39578
    
  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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How do I read and write text files with different character sets?
 
Similar Threads
Copying MS Access Database
spaces in String
fileREader and FileWriter
Reading from file A, writing to file B
File IO with Servlet