nick5454
asked on
simple applet file loading question
error = no protocol
whats wrong with theis. i have no time to figure it out thanks
BufferedReader mudFile;
FileReader file;
try {
boolean isControlSet = false;
/* parse the file */
java.net.URL url = new java.net.URL( getMudFileName() );
//document = builder.parse( url.openStream() );
file = new FileReader( getMudFileName() );
mudFile = new BufferedReader( new InputStreamReader( url.openStream() ) );
whats wrong with theis. i have no time to figure it out thanks
BufferedReader mudFile;
FileReader file;
try {
boolean isControlSet = false;
/* parse the file */
java.net.URL url = new java.net.URL( getMudFileName() );
//document = builder.parse( url.openStream() );
file = new FileReader( getMudFileName() );
mudFile = new BufferedReader( new InputStreamReader( url.openStream() ) );
oh, and i was talking about the java.net.URL constructor ;)
you might need to prefix getMudFileName() with getDocumentBase()
ASKER
the file path is correct. getMudFileName is just a verified path. it gives me a no protocol error where as with parseXML it works.
so what does the no protocol mean?
so what does the no protocol mean?
> the file path is correct. getMudFileName is just a verified path
file path or url?
you do:
java.net.URL url = new java.net.URL( getMudFileName() );
AND
file = new FileReader( getMudFileName() );
java.net.URL constructor requires you to specify port, host, port (if applicable, default is 80), and file.
so if getMudFileName returns something like "/usr/mud/mudfile", then the string you are passing to the constructor is incorrect. it's looking for something more like:
new URL("http://someserver.com/usr/mud/mudfile")
file path or url?
you do:
java.net.URL url = new java.net.URL( getMudFileName() );
AND
file = new FileReader( getMudFileName() );
java.net.URL constructor requires you to specify port, host, port (if applicable, default is 80), and file.
so if getMudFileName returns something like "/usr/mud/mudfile", then the string you are passing to the constructor is incorrect. it's looking for something more like:
new URL("http://someserver.com/usr/mud/mudfile")
oops, specify port, host, port should read
specify protocol, host, port
specify protocol, host, port
can you show us the result of getMudFileName()?
are you trying to get the file from server or client's local hdd?
are you trying to get the file from server or client's local hdd?
ASKER
from the server
mudfilename = getCodeBase() + "textMud.csv";
its located in the same directory on the pache web server
/webapps/companyname/jsp/
mudfilename = getCodeBase() + "textMud.csv";
its located in the same directory on the pache web server
/webapps/companyname/jsp/
I would suggest you to just print out getMudFileName() to see what exactly it is. thanks.
ASKER
I di and its going to the right place. i did a file test in the property to see that it exists.
I do the same thing with a parse xml method and it works. guess i'll just play with it
I do the same thing with a parse xml method and it works. guess i'll just play with it
>> I di and its going to the right place
can you post it?
can you post it?
ASKER
what do you mean by post? confused
there is an header.xml that i read using the same method
getCodeBase() + "header.xml";
this was with the ? asked before
http://207.68.164.250/cgi-bin/linkrd?_lang=EN&lah=303dbea3c0ef80ed4a145de1253125ef&lat=1046060931&hm___action=http%3a%2f%2fwww%2eexperts%2dexchange%2ecom%2fWeb%2fWeb_Languages%2fJSP%2fQ_20524370%2ehtml
about the applet readin xml with io error.
I then used your advice on the question to bring it to a buffered reader class so I can read line by line.
it tells me there is no protocol, it cant be a location because i printed it out and i would also get an io error on the stack. The point is, is what does the no protocol mean? is that saying it cant read a file using that method becuase a buffered readers stream is not compatable with the url class?
there is an header.xml that i read using the same method
getCodeBase() + "header.xml";
this was with the ? asked before
http://207.68.164.250/cgi-bin/linkrd?_lang=EN&lah=303dbea3c0ef80ed4a145de1253125ef&lat=1046060931&hm___action=http%3a%2f%2fwww%2eexperts%2dexchange%2ecom%2fWeb%2fWeb_Languages%2fJSP%2fQ_20524370%2ehtml
about the applet readin xml with io error.
I then used your advice on the question to bring it to a buffered reader class so I can read line by line.
it tells me there is no protocol, it cant be a location because i printed it out and i would also get an io error on the stack. The point is, is what does the no protocol mean? is that saying it cant read a file using that method becuase a buffered readers stream is not compatable with the url class?
can you post the result of getMudFileName() ?
when we say url, it should be like http://www.server.com/file.html , ftp://ftp.server.com/file.zip
http and ftp is protocol.
when we say url, it should be like http://www.server.com/file.html , ftp://ftp.server.com/file.zip
http and ftp is protocol.
ASKER
strange! remove
file = new FileReader( getMudFileName() );
from your code.
if you still have problem, post the full stacktrace.
thanks.
file = new FileReader( getMudFileName() );
from your code.
if you still have problem, post the full stacktrace.
thanks.
ASKER
thanks for the effort
ASKER
ok heres the deal. you were right,
I am using File object to validate the path, but its erroring becuase I have to use a url.
the problem now:
uri = new java.net.URI(mudFileName);
File testMudFileName = new File( uri );
the stack trace is
java.lang.IllegalArgumentE xception: URI scheme is not "file"
at java.io.File.<init>(File.j ava:324)
at mudHistory.setMudFileName( mudHistory .java:248)
at testApplet.init(testApplet .java:156)
at sun.applet.AppletPanel.run (AppletPan el.java:34 7)
at java.lang.Thread.run(Threa d.java:536 )
if its not a file how do I massage it into one. I can get a URL but I dont know how to transform the fragment. Whats the best way?
thanks,
nick
I am using File object to validate the path, but its erroring becuase I have to use a url.
the problem now:
uri = new java.net.URI(mudFileName);
File testMudFileName = new File( uri );
the stack trace is
java.lang.IllegalArgumentE
at java.io.File.<init>(File.j
at mudHistory.setMudFileName(
at testApplet.init(testApplet
at sun.applet.AppletPanel.run
at java.lang.Thread.run(Threa
if its not a file how do I massage it into one. I can get a URL but I dont know how to transform the fragment. Whats the best way?
thanks,
nick
ASKER
the mudFileName is correct this time.
>> I am using File object to validate the path
you cannot use File object in applet to access file in server, it's logically not correct. applet run on client machine, the File ojbect can only access files on user's PC only when applet is signed and given necessary permision.
you cannot use File object in applet to access file in server, it's logically not correct. applet run on client machine, the File ojbect can only access files on user's PC only when applet is signed and given necessary permision.
ASKER
ok, so what method do you suggest I use to validate the file name in a property?
what exactly are you trying to do?
open a connection to your mudfile (which i'm assuming resides on some remote server)
read the contents of it
then what? you want to save it to a file on local machine?
open a connection to your mudfile (which i'm assuming resides on some remote server)
read the contents of it
then what? you want to save it to a file on local machine?
we are a little lost. what do you mean by validate? why do you have to use File object which can only acess files on client's machine? isn't that you are dealing with files on server?
ASKER
Well actuall it reads in files off of the server in the jsp directory.
I set the property setMudFileName. In there I want to validate that I have this file there, because if the data entry clerk doesnt run the script it wont be there.
So I thought if used the file objects exists method I could determine if its there.
I have a Java2D applet that processes tons of data and creates charts based on that data, so if I could know if it exists first it would be great.
thanks,
nick
I set the property setMudFileName. In there I want to validate that I have this file there, because if the data entry clerk doesnt run the script it wont be there.
So I thought if used the file objects exists method I could determine if its there.
I have a Java2D applet that processes tons of data and creates charts based on that data, so if I could know if it exists first it would be great.
thanks,
nick
if it doesn't exist:
when you do: url.openStream(...) it will throw an IOException
when you do: url.openStream(...) it will throw an IOException
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
very cool, you deserve more points but in this economy as a consultant I'm struggling.
thanks
thanks
> you deserve more points but in this economy as a consultant I'm struggling.
lol
lol
you are welcome. I myself is a consultant so I understnad. That's already a lot points, I appreciate it :D
let me know if you have further enquires.
let me know if you have further enquires.
using the constructor you are using it most include protocol (ie. http://blah.blah.blah, ftp://blah.blah.blah, etc)