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

    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
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    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
    Posts
    2
    Rep Power
    0

    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:
    MainClass
    --Map
    --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
    appeared.

    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, 06:41 PM
  2. Program Runs in NetBEans but Not in cmd
    By MeathUltra in forum NetBeans
    Replies: 1
    Last Post: 12-09-2008, 05:38 AM
  3. Replies: 2
    Last Post: 09-12-2008, 06:10 PM
  4. Replies: 7
    Last Post: 06-05-2008, 03:54 PM
  5. Problem in opening a file
    By Raghav kv in forum New To Java
    Replies: 1
    Last Post: 08-11-2007, 01: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
  •