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!

Reading text files without specifying the encoding?

807603Oct 22 2007 — edited Oct 24 2007
I have looked everywhere for a solution, but I can't find one. The problem is that I'm using codes that everybody is using, but for some reason, my codes aren't working.

I want to be able to open up text files in Java without having to specify the encoding for the files that I'm going read, because I have no idea which encoding they will use.

But even when specifying UTF-8 to be encoding of the file to read, it doesn't work correctly:

FileInputStream fileIS= new FileInputStream("somefile.txt");
Reader reader = new BufferedReader(new InputStreamReader(fileIS, Charset.forName("UTF-8")));

EVERYWHERE I look, ppl are using these codes! But it doesn't work, some characters (such as the Euro sign) are displayed as squares.

However, I want to be able to read not only UTF-8 files but anything that Java supports. Any ideas?

Edited by: Stalfos on Oct 22, 2007 12:22 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 21 2007
Added on Oct 22 2007
66 comments
1,677 views