Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Compiles, Doesn't run

    This code throws a FileNotFoundException. The file, "primary.input" is in the project folder which is in the same directory as all of the class files and java files.


    package proj3;
    import java.util.*;
    import java.io.*;



    class Main
    {

    public static void main(String[]args) throws FileNotFoundException
    {
    File fl = new File("primary.input");
    FileReader f = new FileReader(fl);
    BufferedReader br = new BufferedReader(f);
    Stackz s;
    try
    {
    while(br.ready())
    {
    String theString = br.readLine();
    s = new Stackz(theString);
    }
    }
    catch(IOException e){}
    }

    }


    and here is the error the runtime gets:
    ----jGRASP exec: java proj3.Main

    Exception in thread "main" java.io.FileNotFoundException: primary.input (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:106)
    at java.io.FileReader.<init>(FileReader.java:55)
    at proj3.Main.main(Main.java:13)

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.


    I can give the other classes if they are needed, so let me know if that will help.

    Thanks

  • #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    Can you please list your directory structure, starting from the place where you are running the java program. (including files)
    "To iterate is human, to recurse divine." -L. Peter Deutsch

  • #3
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here is the directory path:

    C:\Documents and Settings\Pat\My Documents\Class ****\CSci341\proj3

    everything is in the the proj3 directory, class and java files, as with the input file

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    And you are sure the file is called primary.input and NOT primary.input.txt?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yes the file is called primary.input I took it directly from my teachers files off of our server...and the projects before have all had the exact same file input name. And so far, the projects from before were in perl and they all worked.

    This just doesn't make any sense.


    One of my friends thinks it might have something to do with the packaging. I'm not sure since the file is in the package directory
    Last edited by holycow02; 04-08-2008 at 07:27 PM.

  • #6
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    try putting the file one directory back and see if it will pick it up then. If that doesn't work then you need need to do something like this:

    Code:
    File f = new File("primary.input");
    System.out.println(f.getAbsolutePath());
    Let us know what it prints out. I have a suspicion on what it is but I'd like to have that printed out before I say.
    "To iterate is human, to recurse divine." -L. Peter Deutsch

  • Users who have thanked Aradon for this post:

    holycow02 (04-08-2008)

  • #7
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This is what it prints:
    C:\Documents and Settings\Pat\My Documents\Class ****\CSci341\primary.input

    after I moved it up one directory.

    Now im getting a nullpointerexception which is something with my array so I think you fixed it.

    Thanks a bunch


  •  

    Posting Permissions

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