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 7179799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:12:50+00:00 2026-05-28T17:12:50+00:00

I’m new to the programming world, and I am trying to do a simple

  • 0

I’m new to the programming world, and I am trying to do a simple program where I read and output a single number from a file. I believe I set everything up right in the code, do I need to do anything special with the location of the .txt file to make the program read the file?

package pack;

import java.util.*;

import java.io.*;

public class Ch2_PrExercise17 {

    public static void main(String[] args)
            throws FileNotFoundException{

        Scanner inFile = new Scanner(new FileReader("inData.txt"));
        int num1;
        num1 = inFile.nextInt();
        System.out.println(num1);
    }
}

The exception I get is as follows;

Exception in thread "main" java.io.FileNotFoundException: inData.txt (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileReader.<init>(Unknown Source)
    at pack.Ch2_PrExercise17.main(Ch2_PrExercise17.java:8)
  • 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-05-28T17:12:50+00:00Added an answer on May 28, 2026 at 5:12 pm

    If Eclipse is really saying “source not found” then it is talking (at that point) about the source code of something.

    If you are managing to run the class from Eclipse, then Eclipse has been able to compile it, so it knows where the source code is. So it must be the source code of something else. My best guess is that it can’t find the source code for the standard Java class library, and that probably means that Eclipse is running on a JRE installation not a JDK installation.

    (If my theory is correct, then the “source not found” text is embedded in the exception stacktrace …)

    It might also be a build problem but I doubt it, because if the class wasn’t building you’d see error markers when you view the source file in eclipse, and Eclipse would complain when you tried to run it. Eclipse would also complain if the source file was in the wrong directory.


    The second part of the problem is getting your application to find the "inData.txt" file. That should be simple. When you try to open a file with a relative pathname, the Java libraries will try to resolve the pathname relative to the application’s “current directory”. By default, when you run the application from Eclipse, this will be the directory your shell was in when you launched Eclipse; e.g.

    $ cd /home/josh/somedir
    $ eclipse &
    

    … and the default current directory should be “/home/josh/somedir”.

    If the default current directory is not right, you have a number of options, including:

    • Change directory to the right one before launching Eclipse.
    • Use Eclipse’s “Run Configurations” panel to select your application’s launch configuration, and change the launcher’s current directory setting.
    • Change the relative pathname in the source code to the correct absolute pathname for the file.

    FOLLOW-UP

    Exception in thread "main" java.io.FileNotFoundException: inData.txt (The system cannot find the file specified) 
      at java.io.FileInputStream.open(Native Method) 
      at java.io.FileInputStream.<init>(Unknown Source)
      at java.io.FileInputStream.<init>(Unknown Source) 
      at java.io.FileReader.<init>(Unknown Source) 
      at pack.Ch2_PrExercise17.main(Ch2_PrExercise17.java:8)
    

    The “Unknown Source” messages mean that the JVM (not Eclipse) cannot find the information it needs to produce a full stacktrace. You appear to be executing using an “rt.jar” file that has debug information stripped. You can ignore this issue, but to fix it you would need to look into what JVM is being uses, and why the “rt.jar” has no debug info.

    The real problem is the FileNotFoundException exception, and my diagnosis of that (as above) stands. The “current directory” is not what it needs to be for that relative pathname to resolve. See above for possible solutions.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.