Results 1 to 3 of 3
  1. #1
    fauzilhaqqi is offline Member
    Join Date
    Dec 2008
    Rep Power

    Exclamation Opening file, runs in NetBeans but CommandPrompt

    I have a problem, I can't solve it yet.

    As i know, package is necessary to create jar file. I use netbeans 6.1 to read file. Please see my code:

    void loadFile(String fileName) {
    URL url = getClass().getResource(fileName);
    String path = url.getFile();
    File file = new File(path);
    FileReader fr = new FileReader(file);
    ....other codes

    nah, the error comes in "file" line. If I run this method in NetBeans, it will run. No problem with another code to read the file. But after I build the jar file, and run it from cmd, an error occured. System cannot find the file. Why? Please give any sollution... I really need it as soon as possible.

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Rep Power


    Where is your "file" located and where are you running program from ?
    dont worry newbie, we got you covered.

  3. #3
    fauzilhaqqi is offline Member
    Join Date
    Dec 2008
    Rep Power

    Exclamation I try another sollution, but still error

    URL url = getClass().getResource(mapFolder + fileName);
    String path = url.toString();
    URI aa = URI.create(path);
    File fl = new File(aa);

    Here is my file allocation:
    --another folder

    The codes work if I run using NetBeans. An error occured after I build the file into jar file. I run it at command prompt, and
    java.lang.IllegalArgumentException: URI is not hierarchical

    I don't have any problem when just getting image with method getClass().getResource(ImageFolder + fileName);

    I try another method, like this:
    URL url = getClass().getResource(mapFolder + fileName);
    String path = url.getFile();
    File fl = new File(path);

    Same problem, it runs in NetBeans, but if I run the jar file in command prompt, exception show that file not found or filepath is wrong. Why??? :confused:

Similar Threads

  1. [SOLVED] App runs only in IDE
    By hannehomuth in forum Advanced Java
    Replies: 4
    Last Post: 07-15-2009, 07:41 PM
  2. Program Runs in NetBEans but Not in cmd
    By MeathUltra in forum NetBeans
    Replies: 1
    Last Post: 12-09-2008, 06:38 AM
  3. Replies: 2
    Last Post: 09-12-2008, 07:10 PM
  4. Replies: 7
    Last Post: 06-05-2008, 04:54 PM
  5. Problem in opening a file
    By Raghav kv in forum New To Java
    Replies: 1
    Last Post: 08-11-2007, 02:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts