Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7876123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:07:12+00:00 2026-06-03T03:07:12+00:00

I’m getting a FileNotFoundException when running the following Java 6 code on Eclipse (Indigo)

  • 0

I’m getting a FileNotFoundException when running the following Java 6 code on Eclipse (Indigo) on Snow Leopard:

import java.io.*;
import java.util.*;

public class readFile {

    public static void main(String[] args) {

        Scanner s = new Scanner(new FileReader("/Users/daniel/pr/java/readFile/myfile.txt"));  // Line 9

    }
}

The exception is

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Unhandled exception type FileNotFoundException

    at readFile.main(readFile.java:9)

My current workspace is /Users/daniel/pr/java. It contains only one project (readFile), and the file hierarchy looks like this:

- readFile
    - src
        - (default package)
            - readFile.java
    - JRE System Library [JavaSE-1.6]
    - myfile.txt

After reading several very similar questions, I’ve tried

  • placing copies of myfile.txt in the project, bin, src, and workspace directories, as well as my home and root folders
  • identifying the working directory and using a relative path
  • manually setting the workspace via “Run Configurations > Arguments > Working Directory” in Eclipse
  • running the program with the command line Java launcher in the bin, readFile, src, and java directories (with copies of myfile.txt in all of these places)
  • removing the file extension and/or lengthening the filename (above some supposed minimum character limit), and
  • verifying the permissions of myfile.txt (they’re now rw-r–r–).

I’m at a loss. What could be the problem? (Thank you for reading!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:07:13+00:00Added an answer on June 3, 2026 at 3:07 am

    The exception tells you the problem.

    The code you have in your main might throw a FileNotFoundException, so you need to consider that in your code, either by declaring in the method signature that that exception can be thrown, or by surrounding the code with a try catch:

    Declaring:

    public static void main(String[] args) throws FileNotFoundException{
    
        Scanner s = new Scanner(new FileReader("/Users/daniel/pr/java/readFile/myfile.txt"));  // Line 9
    
    }
    

    Or using try/catch

    public static void main(String[] args) {
        try { 
            Scanner s = new Scanner(new FileReader("/Users/daniel/pr/java/readFile/myfile.txt"));  // Line 9
        } catch (FileNotFoundException e) {
            //do something with e, or handle this case
        }
    }
    

    The difference between these two approaches is that, since this is your main, if you declare it in the method signature, your program will throw the Exception and stop, giving you the stack trace.

    If you use try/catch, you can handle this situation, either by logging the error, trying again, etc.

    You might want to give a look at:
    http://docs.oracle.com/javase/tutorial/essential/exceptions/ to learn about exception handling in Java, it’ll be quite useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.