Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UTF-8 query problem

 
Sai Narasimha Reddy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm developing a web-based setup wizard for my appliation. it reads a utf-8 encoded file and executes the queries in the file.

my reading code...



when i read the file using the above code, i'm getting a '?' symbol as a very first character. due to that i'm getting a Exception saying ..


[ July 27, 2008: Message edited by: Scott Selikoff ]
 
Sai Narasimha Reddy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i display the first line read from the file in my windows-cmd prompt, the weird '?' is displayed there too.....

does it mean that all the JDBC-queries are ANSI encoded??.....i know that's stupid of me saying that......

but i urgently need a solution for this problem.....

see this tutorial's output.....the users there also posted that they're having the same problem!
http://www.roseindia.net/java/example/java/io/ReadUTF8.shtml
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps your file has a BOM (Byte Order Mark) at the beginning? Look at it with a hex editor to find out. And if so, skip over it before trying to use the contents of the file.
 
Sai Narasimha Reddy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why doesn't java filter that BOM before giving me the file contents??....i've read the file using "utf-8" character encoding only.....



did anybody face the same problem??

is there any way out of this without i having to ignore the BOM manually??.....does this problem occur only in windows or it occurs in linux also??. If it doesn't occur in linux then how to make my code portable??
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it doesn't. And no, you aren't the only one in the world to experience this problem. And I expect it's the same in Unix as it is in Windows, although it wouldn't be that hard to just try it if that wasn't just a rhetorical question.

If you know in advance that there's going to be a BOM then it's just a couple of lines of code to skip over it. If you don't, it's a little bit more complicated (and a PushbackInputStream can help).
 
Sai Narasimha Reddy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks paul......for the PushbackInputStream suggestion!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic