Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: 'Can't find file' error

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 'Can't find file' error

    I can't find why this is not working. Here's my code, and then the error.

    import java.util.*;
     
    import java.io.*;
     
    public class CordreyLab6 {
     
     
    	public static void main(String[] args) throws IOException {
     
    		// get user input for file name
    		Scanner console = new Scanner(System.in); // for user input of file name
    		System.out.println("Please enter a file name: ");
    		String userFile = console.nextLine();
     
    		// read file and  pass to process method
    		Scanner input = new Scanner(new File (userFile));
    		processFile(input, console);
     
    	}// end main

    The error is:
    Please enter a file name:
    Lab6Input.txt
    Exception in thread "main" java.io.FileNotFoundException: Lab6Input.txt (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.util.Scanner.<init>(Unknown Source)
    at CordreyLab6.CordreyLab6.main(CordreyLab6.java:17)

    I've put copies of the text file in all the folders I think I could be looking in- the class folder, the c:\root, the src folder, under the sink. I wish I knew what folders and files were created when Eclipse creates a java program. Obviously there is quite a bit more going on than just the source code folder. I don't know where the program is expecting to find the file, so I'm just guessing on where to put it. I suspect there is a better way.

    Thank you so much for the help!


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,669
    Thanks
    25
    Thanked 327 Times in 304 Posts

    Default Re: 'Can't find file' error

    You can find out. Create a new File, write it, then invoke the File.getAbsolutePath() method on your new file and print out the result. In theory, that should give you the exact path.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Banned
    Join Date
    Apr 2012
    Posts
    38
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: 'Can't find file' error

    you can add this
    final class manusia {
    int tinggi, berat;
    void bernyanyi(){ System.out.println(“Tralala..lilili”); } }
    class bapak extends manusia { <class body > }// salah

Similar Threads

  1. Please Help me Find the Error
    By jugalrockz in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 18th, 2012, 01:31 AM
  2. error :cannot find symbol
    By iswan in forum AWT / Java Swing
    Replies: 1
    Last Post: October 1st, 2011, 08:26 AM
  3. Can't find file (not sure the error)
    By KILL3RTACO in forum File I/O & Other I/O Streams
    Replies: 21
    Last Post: September 1st, 2011, 01:17 AM
  4. can any one plz find the error.
    By shalini_sns in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 23rd, 2011, 05:26 PM
  5. Need help, cannot find error
    By Imeri0n in forum What's Wrong With My Code?
    Replies: 13
    Last Post: December 5th, 2010, 04:26 PM