This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes How to write to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to write to a file" Watch "How to write to a file" New topic

How to write to a file

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9967


I want to write to a file using the Charset API/UTF-8 encoding format. Basically I have a StringBuffer whose contents are in html/ASCII format. I want to use the Charset API and convert this to UTF-8 format and then write the o/p to a file. Any ideas on how to do this?

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
If the data is in ASCII, then you don't need to do any conversion - ASCII is a subset of Unicode. Just specify UTF-8 as encoding when writing the data to the file, and you should be all set.
I agree. Here's the link:
subject: How to write to a file
It's not a secret anymore!