FileNotFoundException when using FileInputStream

Posted by user1672817 on Stack Overflow See other posts from Stack Overflow or by user1672817
Published on 2012-09-15T03:35:48Z Indexed on 2012/09/15 3:37 UTC
Read the original article Hit count: 178

I am trying to access a file I have contained in the jar.

The beginning of my code is as follows:

import java.io.*;
import java.net.*;

public class intro {
public static void main(String[] args) throws IOException{

    URL jarUrl = intro.class.getResource("myFile.jar");
    File myJar = new File(jarUrl.toString());

    FileInputStream fis = new FileInputStream(myjar);
}

I'm getting the following error:

Exception in thread "main" java.io.FileNotFoundException: file:\...myFile.jar (The filename, directory name, or volume label syntax is incorrect)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at intro.main(intro.java:10)

It seems to have no problem finding the URL or initializing the file, but I can't get the FileInputStream to work. Does anybody know what I'm doing wrong? Help would be appreciated.

© Stack Overflow or respective owner

Related posts about java

Related posts about filenotfoundexception