|
-
Read a file but does not do it twice
Hi, hope someone can help as Java is a bit tricky!
I have javascript code which calls a java applet, and this applet reads a file and passes the file contents back to javascript. That all works fine.
The problem is that if I ask the java applet for the file contents again it gives me the contents that it read the first time round. As I am resetting the javascript variables it can only be the java code at fault.
javascript:
probs="";
p="";
probs = document.readerApplet.sendtext(p)
<APPLET CODE="Test4.class" NAME="readerApplet" WIDTH="1" HEIGHT="1"></APPLET>
and the java in Test4.class is:
import java.applet.*;
import java.io.*;
import java.awt.*;
public class Test4 extends Applet
{
String me;
String thisLine;
public void init()
{
readTextFromJar("devlist.htm");
}
public void readTextFromJar(String s)
{
try
{
InputStream is = getClass().getResourceAsStream(s);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while ((thisLine = br.readLine()) != null)
{
thisLine += thisLine;
me += thisLine;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public String sendtext(String thetext)
{
return me;
}
}
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks