FileInputStream returns FileNotFoundException on Apple Mac

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jacqueline Snook

    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.propert ies.

    When I give this as a String reference to FileInputStream in Java, it
    returns a FileNotFoundExc eption, quoting
    "file:/Users/networkserver/SmartAV-CMS/smartav.propert ies (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
  • Fahd Shariff

    #2
    Re: FileInputStream returns FileNotFoundExc eption on Apple Mac

    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.propert ies
    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.propert ies" is a URL
    To read this you would have to do something like:

    URL url = new URL("file:///Users/networkserver/SmartAV-CMS/smartav.propert ies")
    ;
    BufferedReader in = new BufferedReader(
    new InputStreamRead er(
    url.openStream( )));

    Hope this makes sense!

    Fahd

    Comment

    • Chris

      #3
      Re: FileInputStream returns FileNotFoundExc eption on Apple Mac

      > I am trying to reference a file on an apple mac from Java. In order[color=blue]
      > 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.propert ies.
      >
      > When I give this as a String reference to FileInputStream in Java, it
      > returns a FileNotFoundExc eption, quoting
      > "file:/Users/networkserver/SmartAV-CMS/smartav.propert ies (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.[/color]

      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

      Comment

      • Jacqueline Snook

        #4
        Re: FileInputStream returns FileNotFoundExc eption on Apple Mac

        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!!


        sarge_chris@hot mail.com (Chris) wrote in message news:<568394b1. 0405120413.71fc 3cbe@posting.go ogle.com>...[color=blue][color=green]
        > > 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.propert ies.
        > >
        > > When I give this as a String reference to FileInputStream in Java, it
        > > returns a FileNotFoundExc eption, quoting
        > > "file:/Users/networkserver/SmartAV-CMS/smartav.propert ies (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.[/color]
        >
        > 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[/color]

        Comment

        Working...