?
Solved

simple applet file loading question

Posted on 2003-02-21
28
Medium Priority
?
190 Views
Last Modified: 2010-04-01
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
Comment
Question by:nick5454
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 10
  • 7
28 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 7995164
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 7995169
oh, and i was talking about the java.net.URL constructor ;)
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 7996794
you might need to prefix getMudFileName() with getDocumentBase()
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:nick5454
ID: 8003863
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 8004378
> 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
 
LVL 18

Expert Comment

by:bobbit31
ID: 8004383
oops,  specify port, host, port  should read
specify protocol, host, port
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8005904
can you show us the result of getMudFileName()?

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

Author Comment

by:nick5454
ID: 8005921
from the server


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

/webapps/companyname/jsp/
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8006033
I would suggest you to just print out getMudFileName() to see what exactly it is. thanks.
0
 

Author Comment

by:nick5454
ID: 8006048
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8006150
>> I di and its going to the right place
can you post it?
0
 

Author Comment

by:nick5454
ID: 8006172
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8006232
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
 

Author Comment

by:nick5454
ID: 8006251
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8006296
strange! remove
file = new FileReader( getMudFileName() );
from your code.

if you still have problem, post the full stacktrace.
thanks.
0
 

Author Comment

by:nick5454
ID: 8006538
thanks for the effort
0
 

Author Comment

by:nick5454
ID: 8009585
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
 

Author Comment

by:nick5454
ID: 8009593
the mudFileName is correct this time.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8010004
>> 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
 

Author Comment

by:nick5454
ID: 8027415
ok, so what method do you suggest I use to validate the file name in a property?

0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8027443
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
 
LVL 14

Expert Comment

by:kennethxu
ID: 8027641
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
 

Author Comment

by:nick5454
ID: 8027670
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 8027736
if it doesn't exist:
when you do: url.openStream(...) it will throw an IOException
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 800 total points
ID: 8027754
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
 

Author Comment

by:nick5454
ID: 8027789
very cool, you deserve more points but in this economy as a consultant I'm struggling.

thanks
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8027795
> you deserve more points but in this economy as a consultant I'm struggling.

lol
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8027847
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question