• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

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() ) );
0
nick5454
Asked:
nick5454
  • 11
  • 10
  • 7
1 Solution
 
bobbit31Commented:
what's getMudFileName() return?

using the constructor you are using it most include protocol (ie. http://blah.blah.blah, ftp://blah.blah.blah, etc)
0
 
bobbit31Commented:
oh, and i was talking about the java.net.URL constructor ;)
0
 
kennethxuCommented:
you might need to prefix getMudFileName() with getDocumentBase()
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nick5454Author Commented:
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?
0
 
bobbit31Commented:
> 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")
0
 
bobbit31Commented:
oops,  specify port, host, port  should read
specify protocol, host, port
0
 
kennethxuCommented:
can you show us the result of getMudFileName()?

are you trying to get the file from server or client's local hdd?
0
 
nick5454Author Commented:
from the server


mudfilename = getCodeBase() + "textMud.csv";
its located in the same directory on the pache web server

/webapps/companyname/jsp/
0
 
kennethxuCommented:
I would suggest you to just print out getMudFileName() to see what exactly it is. thanks.
0
 
nick5454Author Commented:
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
0
 
kennethxuCommented:
>> I di and its going to the right place
can you post it?
0
 
nick5454Author Commented:
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?
0
 
kennethxuCommented:
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.
0
 
nick5454Author Commented:
0
 
kennethxuCommented:
strange! remove
file = new FileReader( getMudFileName() );
from your code.

if you still have problem, post the full stacktrace.
thanks.
0
 
nick5454Author Commented:
thanks for the effort
0
 
nick5454Author Commented:
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.IllegalArgumentException: URI scheme is not "file"

     at java.io.File.<init>(File.java:324)

     at mudHistory.setMudFileName(mudHistory.java:248)

     at testApplet.init(testApplet.java:156)

     at sun.applet.AppletPanel.run(AppletPanel.java:347)

     at java.lang.Thread.run(Thread.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
0
 
nick5454Author Commented:
the mudFileName is correct this time.
0
 
kennethxuCommented:
>> 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.
0
 
nick5454Author Commented:
ok, so what method do you suggest I use to validate the file name in a property?

0
 
bobbit31Commented:
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?
0
 
kennethxuCommented:
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?
0
 
nick5454Author Commented:
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
0
 
bobbit31Commented:
if it doesn't exist:
when you do: url.openStream(...) it will throw an IOException
0
 
kennethxuCommented:
OK, if you want to know the situation when a file is not exist, try this:

InputStream in = null;
try {
  in = url.openStream();
} catch( java.io.FileNotFoundException e ) {
  // file not exist on server.
}

you can then use if( in == null ) later in your code to see if file exist.
0
 
nick5454Author Commented:
very cool, you deserve more points but in this economy as a consultant I'm struggling.

thanks
0
 
bobbit31Commented:
> you deserve more points but in this economy as a consultant I'm struggling.

lol
0
 
kennethxuCommented:
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 11
  • 10
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now