0

I am trying to upload files by ftp using the apache common library. I want to keep those file inside the jar, since these are files that will stay the same and need to be uploaded on the different hosts several time.

I am trying the following:

    public void doCGIRecovery() throws IOException{
    System.out.println(getClass().getResource("/cgi/example").getPath());
    FileInputStream file = new FileInputStream(getClass().getResource("/cgi/example").getPath());
    f.storeFile("./", file);
}

Using eclipse this works and the sysout is giving me:

/Users/user/Documents/workspace/example-Project/bin/com/example/java/example/business/cgi/example

But after the compilation into a jar it returns me the following:

file:/Users/user/Desktop/example.jar!/com/example/java/example/business/cgi/example

And I get (No such file or directory).

So how does that come? Further where does the "!" after example.jar come from?

Best Regards

Ilir
  • 430
  • 2
  • 7
  • 19
  • Check this: http://stackoverflow.com/questions/5054435/reading-file-in-jar-using-relative-path – Serhiy Nov 12 '12 at 20:13

1 Answers1

0

Don't worry about messing with the path, use getClass().getResourceAsStream() instead.

Chris Nava
  • 6,614
  • 3
  • 25
  • 31
  • I tried that too, but the problem is, getClass().getResourceAsStream() returns a inputstream, and I need a FileInputStream. And I cannot cast the InputStream to FileInputStream. – Ilir Nov 13 '12 at 07:40
  • Then you may have a problem since items packaged in a .jar aren't individual files any more. The standard File API can't access them directly. – Chris Nava Nov 13 '12 at 19:13