472,805 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

FileInputStream returns FileNotFoundException on Apple Mac

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
3 12478
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
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Patrick | last post by:
Hello all! I am porting an application from C++ to Java and have run into a problem using the DataInputStream reader object. The file I am trying to read in is anywhere from 20 to 60 MB and has a...
1
by: Abhijit Gadekar | last post by:
Hello, I am getting a problem with objectinputstream and fileinputstream. Whenever I try to close a ObjectInputStream object it gives an Exception. And if I try to delete the associated file on...
1
by: ulf | last post by:
Hello, After I got a FileNotFoundException in my real life CSharp code, I nailed it down to the following line: System.EnterpriseServices.ResourcePool rp = new...
0
by: Peter Vestergaard | last post by:
Hi, I am running VS .Net 2005. I have an application in which one of the classes are having a member that is an instance of a class defined in a managed C++ dll. As soon as I try to create an...
6
Nepomuk
by: Nepomuk | last post by:
Hi! I'm trying to transfer files and to do so must, of course, read them. Now, my reference File has a size of 4.240.821 Bytes and I need something between 9 and 14 seconds to simply read it and...
6
by: Tukeind | last post by:
Hello, I've opened a file (code below) containing file names onto a FileInputStream, and attempting to open each file and place its contents onto a FileOutputStream (or buffer) and need help getting...
2
by: bbindae | last post by:
I am trying to check whether XmlTextReader reads the xml file successfully or not. MSDN says that XmlTextReader raise the FileNotFoundException when it cannot find the file to read. Here is...
29
Niheel
by: Niheel | last post by:
The Apple invasion into corporate has started and I can't say if I am excited or scared. As an IT manager, I have nightmares over all the support and technical issues of integrating Apple hardware...
1
thatos
by: thatos | last post by:
I have the class TableCollection which creates tables for data store in the given direcoty, the method which reads this goes like this. public void read(String dirname,String regex) throws...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.