Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

UTF-8 file reading: the first character issue

807580May 18 2010 — edited May 25 2010
Hi,
A file foo.sql is saved as UTF-8 encoding using Windows notepad.

Then the following code did not read the text content correctly.

InputStreamReader isr = new InputStreamReader(new FileInputStream("foo.sql"), "UTF-8");
BufferedReader reader = new BufferedReader(isr);
String line = reader.readLine();

From debug, the first character is not displayable. for example,

foo.sql
----------
create table school

the line from BufferedReader is
?create table school

the question mark means the char is not displayable. What is the correct way to read UTF-8 encoded text file?

Thanks for help.
Dave
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 22 2010
Added on May 18 2010
7 comments
4,239 views