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!

read unicode text file

807605Sep 7 2007 — edited Sep 7 2007
Hi,

I want to read a text file that has some unicode (\u0259) chars and some regular chars. An example line from the text file:
a=,\u0251,e=,\u0259,e*,\u025b,i*,\u026a,n=,\u014b,?,\u0294

Here is my code:
FileInputStream fInputStream = new FileInputStream(file);
BufferedReader bReader = new BufferedReader(new InputStreamReader(fInputStream, "UTF8"));
                
String line = null;
while ((line = bReader.readLine()) != null) {
     String[] schemes = line.substring(0).split(",");
      . . . pair off the elements in the line and add them to an ArrayList . . .
}
My problem is in that it reads the \ char as a char and not a unicode escape character. Watching the line or schemes variable in NetBeans shows the line above like this:

"a=,\\u0251,e=,\\u0259,e*,\\u025b,i*,\\u026a,n=,\\u014b,?,\\u0294"

Java.lang.string is a bit too helpful here in preserving the slashes. Is there away to get it to read the line without putting the extra slash in there?

If I manually type in the pairs, it displays them correctly.
List pairs = new ArrayList();
pairs.add("a=" + "," + "\u0251");
pairs.add("e=" + "," + "\u0259"); pairs.add("e*" + "," + "\u025b");
pairs.add("i*" + "," + "\u026a");
No double slashes and it displays fine in my program. Any help will be greatly appreciated.

ktx
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 5 2007
Added on Sep 7 2007
4 comments
868 views