Solved

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

Posted on 2006-06-28
1
253 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Eclipse Neon and jdk 1.8.0 11 138
java  and programming certification ? 4 86
recursion example 16 111
ForLoop Example 3 40
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

895 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

12 Experts available now in Live!

Get 1:1 Help Now