This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Using BufferedWriter not able to Write Chinese String  RSS feed

 
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
 
Saloon Keeper
Posts: 4758
117
  • 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.

 
Sheriff
Posts: 23714
50
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
Boost this thread!