By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,032 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

FileInputStream returns FileNotFoundException on Apple Mac

P: n/a
I am trying to reference a file on an apple mac from Java. In order
to find what the URL is supposed to be, I opened it in the Safari web
browser. The directory as returned was
file:///Users/networkserver/SmartAV-CMS/smartav.properties.

When I give this as a String reference to FileInputStream in Java, it
returns a FileNotFoundException, quoting
"file:/Users/networkserver/SmartAV-CMS/smartav.properties (No such
file or directory).

I would like to know how to reference this file, and also maybe why it
takes out 2 of the slashes.

Many thanks in advance,
Jacqueline Snook
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The name of the file you pass to the FileInputStream must be the path
name in the file system.
e.g. /Users/networkserver/SmartAV-CMS/smartav.properties
If you pass this to the FileInputStream it should work.

What you opened in the web browser is a URL.
"file:///Users/networkserver/SmartAV-CMS/smartav.properties" is a URL
To read this you would have to do something like:

URL url = new URL("file:///Users/networkserver/SmartAV-CMS/smartav.properties")
;
BufferedReader in = new BufferedReader(
new InputStreamReader(
url.openStream()));

Hope this makes sense!

Fahd
Jul 17 '05 #2

P: n/a
> I am trying to reference a file on an apple mac from Java. In order
to find what the URL is supposed to be, I opened it in the Safari web
browser. The directory as returned was
file:///Users/networkserver/SmartAV-CMS/smartav.properties.

When I give this as a String reference to FileInputStream in Java, it
returns a FileNotFoundException, quoting
"file:/Users/networkserver/SmartAV-CMS/smartav.properties (No such
file or directory).

I would like to know how to reference this file, and also maybe why it
takes out 2 of the slashes.


FileInputDevice assumes the string argument is a file-path whereas
you're assuming it's an URL. Either pass in just the file-path (i.e.
omit 'file://' from the start) or check out the URL class (you can get
a File object or InputStream from an URL).

Incidentally that's why it strips out the two slashes from the start
of the URL - it automatically removes what are considered as
superfluous separators in the path.

- sarge
Jul 17 '05 #3

P: n/a
Thanks a bunch guys!! I have sorted that problem out now - time to
move on to the next one!!!

(to 10 green bottles)

99 bugs in the program,
99 bugs,
Take one out compile it again,
Now there is 100 bugs in the program!!
sa*********@hotmail.com (Chris) wrote in message news:<56**************************@posting.google. com>...
I am trying to reference a file on an apple mac from Java. In order
to find what the URL is supposed to be, I opened it in the Safari web
browser. The directory as returned was
file:///Users/networkserver/SmartAV-CMS/smartav.properties.

When I give this as a String reference to FileInputStream in Java, it
returns a FileNotFoundException, quoting
"file:/Users/networkserver/SmartAV-CMS/smartav.properties (No such
file or directory).

I would like to know how to reference this file, and also maybe why it
takes out 2 of the slashes.


FileInputDevice assumes the string argument is a file-path whereas
you're assuming it's an URL. Either pass in just the file-path (i.e.
omit 'file://' from the start) or check out the URL class (you can get
a File object or InputStream from an URL).

Incidentally that's why it strips out the two slashes from the start
of the URL - it automatically removes what are considered as
superfluous separators in the path.

- sarge

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.