• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedReader in applet fails to read bigger file

 
Shen Huang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My applet has to read a couple of files from the web server using BufferedReader. It works fine with smaller files upto about 24K, but fails with bigger files. My biggest file size is about 2MB. I used the following code for the quick test. I also tried to use the constructor that takes a size parameter for both BufferedReader and StringBuffer in my test code. The size parameter in the constructor does not seem to make any difference. My brower cache is also set very big. Hope somebody can help me. I am using j2sdk1.4.2, and IE6 on XP.

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.*;
/*
<applet code=ReadFile width=300 height=300 ></applet>
*/
public class ReadFile extends JApplet {
StringBuffer buf;
String FileToRead;
TextArea ta;

public void init() {
ta = new TextArea(40, 40);
ta.setEditable(false);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(ta, "Center");
FileToRead = "my.gtx"; //file size 23K, works!
//FileToRead = "vnc.gtx"; //file size 99K, does not work!
// Now read the file.
readFile(FileToRead);
}
public void readFile(String FileToRead){
String line;
URL url=null;
try {
url = new URL (getCodeBase(), FileToRead );
}
catch (MalformedURLException e ) {
System.out.println("Malformed URL ");
stop();
}
buf = new StringBuffer("This is the first line created by me.\n");
try {
InputStream in=url.openStream();
BufferedReader dis = new BufferedReader(new InputStreamReader(in));
while ((line = dis.readLine()) != null){
buf.append(line + "\n");
}
in.close();
}
catch (IOException e ) {}
buf.append("This line is added by me\n");
// Load the file into the TextArea.
ta.append(buf.toString ());
}
}
 
Shen Huang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
regarding my BufferedReader problem, the IOException trapped by replacing the empty catch block with {buf.append(e.toString() + "\n");} is:
java.net.SocketException:Connection reset
Sounds like there are lots of discussions about this connection reset error, but I have no idea of fixing it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic