Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Ranchers,Clarification on UTF-8 in Java

 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

where are the three junk characters as referred by Henry. ??? or is this the correct output code ???



It looks like I was wrong, while it is 3 junk bytes, the read() method will take it all out as one character -- so you're right, reading one character should be fine.

BTW, where is the code that does a reset(), if it is not junk? You seem to just assume that it is junk -- which means, there is no reason to mark() since you don't intend to reset().

Henry
 
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Lal wrote: i should get 3 junk characters,but now im getting as below
{
The value of k 65279 (what is this referring to)
The value of k 49 which is correct for charValue(1)
The value of k 48 which is correct for charValue(0)
}


I don't know why you think you should get three "junk" characters. It's pretty obvious from what you posted there that the reader has made the BOM into a single character, so your first three characters consist of the BOM and the two characters which follow it. You're making this simple thing far too complicated, I think.
 
Ranch Hand
Posts: 590
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Henry,
Can you please refine this code....please......



It looks like I was wrong, while it is 3 junk bytes, the read() method will take it all out as one character -- so you're right, reading one character should be fine.

BTW, where is the code that does a reset(), if it is not junk? You seem to just assume that it is junk -- which means, there is no reason to mark() since you don't intend to reset().



Code is as below:


Could you please review it once ???
 
Henry Wong
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only issue that I have is here...

BufferedReader bufferedReader = null;



Your previous code used to open the file -- this one doesn't. It just assigns a null. And should get you a null pointer exception when you try to use the buffer reader.

Other minor issues include....

1. Since you only read one character now, there is no reason to have the loop. You can get rid of that.

2. Since UTF-8 characters are less than 256. You can probably get away with checking if it is greater than 256, than if it equals 65279.


But everything else looks great, BTW...

Henry
 
Deepak Lal
Ranch Hand
Posts: 590
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot henry....i need to refine the code again....
Thanks to all the Ranchers.



Will be back with more queries in Java.....

Regards
Deepak Lal
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic