Solved

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

839 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