aspose file tools*
The moose likes Java in General and the fly likes Problem in writing extended ASCII characters into a file in japanese machines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem in writing extended ASCII characters into a file in japanese machines" Watch "Problem in writing extended ASCII characters into a file in japanese machines" New topic
Author

Problem in writing extended ASCII characters into a file in japanese machines

Suren BabuM
Greenhorn

Joined: Jun 19, 2002
Posts: 1
Take for eg., � is a registered sign (falls 174 entry in ASCII table.)
Requirement: To Read this character from database and write into file.
This character is getting returned from database properly. Once i write to file using the following code and opening the file in notepad it is showing as ?. I tried opening in binary mode to check the Hex. value and it is 63 (which is ?) instead of 174 (which is �)
result holds the information fetched from database.
BufferedWriter writer1 = new BufferedWriter ( new FileWriter("FromDatabase_native_CharacterIO.txt") ) ;
writer1.write ( result ) ;
writer1.flush() ;
writer1.close() ;
The following code works fine...
FileOutputStream fos = new FileOutputStream( "FromDatabase_unicode.txt" );
OutputStreamWriter osw = new OutputStreamWriter( fos, "Unicode" );
System.out.println("Encoding: "+ osw.getEncoding()) ;
BufferedWriter bw = new BufferedWriter( osw );
bw.write ( result ) ;
bw.flush() ;
bw.close() ;
I don't want to use encoding to mandate 'Unicode', as i have other problems with that.
Any help is highly appreciated as it is sitting in my head for quite some time troubling a lot.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem in writing extended ASCII characters into a file in japanese machines