dcsimg
Problem with reading till end of the file when the file contains foriegn char
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Margaret_Long
Posted On:   Friday, June 28, 2002 04:39 AM

I am working on a program that reads from an inputstream which uses UTF-8 encoding. It contains foriegn chars. If I use a BufferedReader and read the input as lines, I am able to read till the end of the file. However, foriegn chars will be displayed incorrectly. BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()); String buffer; while ((buffer=in.readLine())!=null) out.println (buffer); I have tried to read the file using InputStreams and convert the charset. I am now able to display the foriegn chars correctly but somehow the program can only read till a quarter of the file. I have defined the connLen to be big enough to read the whole file but the actual cha   More>>

I am working on a program that reads from an inputstream which uses UTF-8 encoding. It contains foriegn chars. If I use a BufferedReader and read the input as lines, I am able to read till the end of the file. However, foriegn chars will be displayed incorrectly.

			
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream());

String buffer;
while ((buffer=in.readLine())!=null)
out.println (buffer);


I have tried to read the file using InputStreams and convert the charset. I am now able to display the foriegn chars correctly but somehow the program can only read till a quarter of the file. I have defined the connLen to be big enough to read the whole file but the actual char read (as returned by the variable ll) is only a quarter of my file size. What is happening? Can someone explain how the charset conversion works?

			
InputStream in = conn.getInputStream();
byte[] raw=new byte[connLen+1];
int ll = in.read(raw, 0, connLen);
String s = new String(raw, "UTF-8"); //The string to be displayed
out.println(s);
   <<Less
About | Sitemap | Contact