wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 41068
    
  43
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 - my free Android networking tools app
 
 
subject: How do I read and write text files with different character sets?
 
Similar Threads
File IO with Servlet
spaces in String
Reading from file A, writing to file B
fileREader and FileWriter
Copying MS Access Database