This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using BufferedWriter not able to Write Chinese String

 
Mohammed Althaf
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi I have Written a Sample Code which has to write a chinese String in a Text File. I have Installed Language Package and Tried to run class as java -Dfile.encoding=UTF-8 Program. Data is not Writing it in Chinese as Expected. Please find the below Code.

public class Program {

public static void main(String... args) {

String str2="C:\\123.txt";

try {
Writer writer = new OutputStreamWriter(
new FileOutputStream(str2), "UTF-8");

BufferedWriter fout = new BufferedWriter(writer);

String s="限公司";//Chinese String

fout.write(s);
writer.toString();
System.out.println( writer.toString());

//Remember to call close.
//calling close on a BufferedReader/BufferedWriter
// will automatically call close on its underlying stream
fout.close();

} catch (IOException e) {
e.printStackTrace();
}

}
}


Please Help for the same.

Regards,
Althaf
 
Tim Moores
Bartender
Posts: 2947
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What *does* happen? And what did you expect instead? How are you checking the results? What do you think writer.toString() does?
 
Mohammed Althaf
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.....


Here i am not asking about System.out.println( writer.toString()); i am very much specific to fout.write(s); .

regards,
Althaf.

 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:What *does* happen? And what did you expect instead? How are you checking the results?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic