• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use URL in applet to read ASCII files in loop

 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I use URL to read file one by one? Shall I close the URL connection?
My purpose is: THere is a lot of ASCII files in one folder called data.
Form web site, I use URL to read one file from this folder, save these data in a float array channel[][], then I draw the array in canvas. After I use URL to read another file and save to channel[][] again, and draw channel again.
I use the following code to read URL, this part code is in a loop to read the file from data folder one by one. It is working in appletviewer, but it don't work in IE. Please, any help?? I have beeing stuck in it for long time.
try{
error=true;
url=new URL(webpath+Long.toString(gg));
conn=url.openConnection();
conn.connect();
InputStreamReader in=new InputStreamReader(conn.getInputStream());
BufferedReader inBuff=new BufferedReader(in);
inBuff.readLine();//read the first line of DAQ file
for(int i=0;i<datanum;i++){
String temp=inBuff.readLine();
int k=0,m=0;
for(int j=0;j<temp.length();j++){
if(temp.charAt(j)!=' '&&temp.charAt(j)!='\t'){
tempchar[k]=temp.charAt(j);
k++;
if(j==temp.length()-1){
String s=String.copyValueOf(tempchar);
float f=Float.parseFloat(s);
channel[i][m]=f;
}
}
else{
String s=String.copyValueOf(tempchar);
float f=Float.parseFloat(s);
channel[i][m]=f;
m++;k=0;
tempchar[6]='0';
}
}
}
inBuff.close();
in.close();
}catch(MalformedURLException e)
{errormessage="readdata:e5:Bad URL";error=false;}
catch(IOException e)
{errormessage="readdata:e6:IO error";error=false;}
finally{
[ April 18, 2004: Message edited by: Ernest Friedman-Hill ]
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more thing, I am using Java 1.2 and IE 6
 
Joe Ess
Bartender
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You left some information out of your problem description, like what error you are getting and where the files you are reading are located (i.e. on the same web server you are loading the applet from, on a different server), but since the applet works in appletviewer but not in IE, my guess is the following:
1. You aren't using the Java plug-in. Microsoft's VM is ancient (version 1.1.4) and doesn't have a lot of the features of the newer versions. You can display a java console to debug this problem.
2. You are trying to download the files off of a server other than the one your applet is downloaded from. Security restrictions limit applets to contacting the server they originated from. This will work inside the appletviewer because the appletviewer runs as an application rather than an applet.
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My data files are in the same folder as my applet. And all of them are on the same web site.
Shall I use Java1.1.4 to complie my applet in order to let IE supprt it? Does Java 1.1.4 support URL as Java 1.2?
Shall I close InputStreamReader as in the followings? I use the following function to check if the URL(http://localhost/filename) exist ot nor. SHall I close it after?
out:{
for (t=0;t<sampleinterval*searchrange;t++){
try{
fileexist=true;
url=new URL(webpath+Long.toString(g));
conn=url.openConnection();
conn.connect();
//inStream1=new InputStreamReader(conn.getInputStream());
InputStreamReader inStream1=new InputStreamReader(conn.getInputStream());
inStream1.close();
}catch(MalformedURLException e)
{errormessage="searchfile:e1: Bad URL";fileexist=false;}
catch(IOException e)
{errormessage="searchfile:e2: IO error";fileexist=false;}
finally{
//inStream1.close();
if(!fileexist){
g++;
}
else{
fileexist=true;
file=g;
tt=t;
break out;
}
}//********end of finally
}//******end of for loop
}//******end of out lable
 
Joe Ess
Bartender
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by may Lee:

Shall I use Java1.1.4 to complie my applet in order to let IE supprt it? Does Java 1.1.4 support URL as Java 1.2?

I don't know that you could find a Java 1.1.4 compiler.
What you should do is open the java console in IE and let us know what error you are getting.
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am so frustrated with this program. Could you please tell me if I can do my job by Java Applet or I should use another program? Thanks a lot inadvance.
My job is: when people input a date on the web site, according to the date,I calculate a number, then according to this number, I search a file name exist or not according to this number, then I read this file and the follwing 20 files and draw the graph lines accourding to data in the 20 files. For example: input 2003, Nov, 11 -> get 725234 ->search files by URL in a loop, I mean from, http://localhost/725034 to http://localhost/725434, then I found the file, http://localhost/725230-> then in Java canvas, read one file, draw it, read next, draw it, totally read 20 files, like read http://localhost/725230, draaw it, then read URL http://localhost/725250,draw it ....http://localhost/725270.. the difference between each file name is 20, I use array to store the data of a file and draw it)
All files are ASCII file, inside is like:
0.2323 0.1254 -0.2563
0.4578 0.2568 0.5896
.....
so They are three lines in the canvas.
I have done some test:
When I only search the file by inout date, it works in IE, I can find the file by URL search.
When I only read a file by URL and draw it in IE, like read http://localhost/725230 into the array and draw, it works.
But when I add the part of reading files by URL in loop, then it cannot read datd into the array. The search part is still working, but the result is not shown in IE right away, I mean if I minimize IE, then maxmize IE again, the serach is shown, but never the data is shown.
I think, it should be able to read ULR in a loop, and draw them, since one is working,but the reality is not working. Even all are working well in appletviewer. I don't have a lot of program experience, I have to finish it soon. Is there any way to make it working in applet? Please, give some advise.
Of couser I cannot ask all the client to install Java plgu-in for it.
I will check how to use Java console to debug. I don't know how to use it yet.
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I check from Java Console in IE, the error is:
java.lang.NoSuchMethodError: java/lang/Float: method parseFloat(Ljava/lang/String F not found
at URLnewDrawdata.readdata
at URLnewDrawdata.actionPerformed
at java/awt/Button.processActionEvent
at java/awt/Button.processEvent
at java/awt/Component.dispatchEventImpl
at java/awt/Component.dispatchEvent
at java/awt/EventDispatchThread.run
Exception occurred during event dispatching:
java.lang.NoSuchMethodError: java/lang/Float: method parseFloat(Ljava/lang/String F not found
at URLnewDrawdata.readdata
at URLnewDrawdata$Mycanvas.paint
at com/ms/awt/WComponentPeer.doClearAndPaint
at com/ms/awt/WComponentPeer.paintNode
at com/ms/ui/windowmanager/PaintRequest.run
at com/ms/ui/windowmanager/RunnableMessage.run
at com/ms/awt/WSystemQueue.getMessage
at com/ms/awt/WEventQueue.getNextEvent
at java/awt/EventDispatchThread.run

Is it because I use "float f=Float.parseFloat(s)"? In my canvas paint, I use another function "readdata" to read characters and change to float, then chane to int to draw. Does it mean AWT cannnot support this function? ANy suggestion? I will also try.
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,
I change the method of
from
String s=....
float f=Float.parseFloat(s)
to
String s=...
Float F=new Float(s)
float f=F.floatValue()
Then, it is working.
Thank very much for your suggestion of debug in Java console IE. How stupid !! Don't how to debug in IE, in fact, I never think it. Even I know there is a kind of VC++ step by step debug before.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic