Solved

How to save a string in UTF-8 format into a txt-file?

Posted on 2006-06-28
1
252 Views
Last Modified: 2008-02-01
In my program I am going to save a string into a txt.file as follow:

...
  StringBuffer output = new StringBuffer("some text...");
  File outputFile = new File("produkt.txt");
  FileWriter out = null;
  // Open the file
  try {
    out = new FileWriter(outputFile);
   } catch (Exception e) {
     e.printStackTrace();
  }
  // Write string in to the file
  try {
  out.write(output.toString());
  out.close();
  }catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
...

But how can I change the program so the file could be saved in UTF-8 format ?
0
Comment
Question by:chenwei
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 30 total points
ID: 17000018
 StringBuffer output = new StringBuffer("some text...");
  File outputFile = new File("produkt.txt");
  Writer out = null;
  // Open the file
  try {
    out = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF8");
   } catch (Exception e) {
     e.printStackTrace();
  }
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now