Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle SQL syntax check  without executing 6 54
how to install java on RHEL image on EC2 4 27
jboss wildfly 10.1 10 90
going to wrong jsp page 2 21
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

772 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