• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic