Re: FileInputStream returns FileNotFoundException on Apple Mac

From: Chris (
Date: 05/12/04

Date: 12 May 2004 05:13:38 -0700

> 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/
> When I give this as a String reference to FileInputStream in Java, it
> returns a FileNotFoundException, quoting
> "file:/Users/networkserver/SmartAV-CMS/ (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

Relevant Pages

  • Re: How java passes object references?
    ... Which everybody knows, it doesn't in Java. ... The reason I think this is a useful clarification is that when you got to the part about how passing by reference might work, it seems you went off track at least partly because you didn't understand the nature of the above. ... is a pointer pointing at the memory block. ... Assignments to local variables, or even to class members, do not allocate memory. ...
  • Re: The Java no pointer big fat lie!
    ... > reference types, it wouldn't be a good comparison. ... and what you can't - and there is a big difference in Java to C and C++. ... You cannot change it in the language itself, ... Thus I would distinguish pointers from ...
  • Re: call by reference
    ... We started learning Java about one month ago, and they just don't believe me when i try to explain that there is a confusion when passing reference types as an argumetn to a function. ... The actual parameter must be an L-value. ...
  • Re: Argument scope
    ... these would likely be a better fit for Java. ... Java doesn't have pass-by-reference, ... It's a mistake to conflate allocation strategies with ... it does support JBC though, although it is unlikely I will have full J2SE support anytime in the near future. ...
  • Re: programming concepts > specific languages
    ... >actually changes the target of the reference passed to 'function2'. ... Java from a source that was not precise about terminology. ... if I have a class MyObject and write ... I thought primitive types in particular behave in the ...