• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with file and writing UTF-8 information into file

 
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post
I have a problem with reading some UTF-8 information from a file and writing it as UTF-8 into another file.
imagine , i have a file that contains some utf-8 text ,(i can read them in windows using notepad/wordpad)
Now i want to write a java application to split the file into some more files and do some changes on them.

here is the method i used to read the file :


and this is how i write the file :



That myChangedText is changed version of String that i read from utf-8 file.

the problem is that information that i see in a.txt are not readable?
even the file signature (EmEditor) shows that it is not a utf file.

i only can read the information if i open the file in OO or MS office , by selecting UTF-8 in select encoding dialog

can some one please help me about this ?
thanks
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FileReader and FileWriter assume that you want to use the default character encoding, which in all likelihood is not UTF-8 (that's also stated in their respective javadocs). Use InputStreamReader and OutputStreamWriter to specify the encoding the files are in.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take care about the Byte Order Mark that some editors and applications will put at the start of a UTF-8-encoded text file, to mark it as such. Java's java.io.Reader generally won't recognise this as a Byte Order Mark, but will instead read it as a few junk characters at the start of the file.
 
reply
    Bookmark Topic Watch Topic
  • New Topic