File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Using BufferedWriter not able to Write Chinese String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Using BufferedWriter not able to Write Chinese String" Watch "Using BufferedWriter not able to Write Chinese String" New topic
Author

Using BufferedWriter not able to Write Chinese String

Mohammed Althaf
Greenhorn

Joined: Apr 05, 2010
Posts: 5


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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Apr 05, 2010
Posts: 5
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Tim Moores wrote:What *does* happen? And what did you expect instead? How are you checking the results?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using BufferedWriter not able to Write Chinese String