Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Using BufferedWriter not able to Write Chinese String

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7230
169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 26955
83
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:What *does* happen? And what did you expect instead? How are you checking the results?

 
reply
    Bookmark Topic Watch Topic
  • New Topic