• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Unable to Write the file in UTF-8

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am unable to write the file in UTF-8 by using the OutputStreamWriter but when i used the "unicode" every thing working fine.

Code :

BufferedWriter oBufferedWriter = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(theResultFile.toString(), true), "UTF-8"));

oBufferedWriter.write(str)

The String which is specified above only contains the Numeric value and English Characters like this : str = "10000000001 E01"

When code is executed and i opened the file in notepad/textpad it shows the file is in the ANSI

But when i used the "unicode" instead of UTF-8 everything works fine . Means when i open the file in Notepad/TextPad it shows file is in Unicode

Can anyone help Why it is not possible to write the file in UTF-8

Thanks in advance for your prompt
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see anything incorrect. Does Notepad show the file incorrectly?

For English letters, numbers and other basic (ascii 0-127) characters UTF-8 encoding is exactly same as ANSI so the same version of the file is in both UFT-8 and ANSI.

Encoding is a property which is not saved with the general text files (only some formats like xml have encoding written into header) so Notepad/Textpad/any program can only guess it. Most text editors (including notepad) allow (or reqire) user to specify the encoding when opening and saving files.

And add some non-ascii characters to the String so you can check if they are properly converted to UFT-8.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic