Name: nt126004 Date: 01/24/2002
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
I tried to read a UTF-16 encoded file, and the VM hangs when reading a
character from it. Below is the code I used for testing.
The freeze happens when the input-file is bigger than 8198 bytes!
I used a plain html-file for testing, converted to unicode with the BOM in
the beginning. Previously I worked with JDK1.3.1 where the error didn't
happen.
After a search in the bugparade I found something about a problem with the
names of the encodings (Bug #4513767), and I tried "UTF16" as encoding,
and this works!!!!
This is the class I used for testing:
import java.io.*;
public class ReadUni {
public static void main(String args[]) throws Exception {
File file = new File(args[0]);
String enc = "UTF-16";
InputStreamReader r = new InputStreamReader(new FileInputStream
(file), enc);
int c;
System.out.println("showing file " + file + ":");
while((c=r.read()) != -1) {
System.out.print((char)c);
}
System.out.println();
System.out.println("File displayed!");
}
}
(Review ID: 135578)
======================================================================
- duplicates
-
JDK-4657074 InputStreamReader loops forever when decoding more than 8192 bytes in UTF-16
-
- Resolved
-