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

  • SEARCH
  • Home
  • 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 9298601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:21:50+00:00 2026-06-18T22:21:50+00:00

Similar questions deal with files on the C: drive, where hardcoding the file path

  • 0

Similar questions deal with files on the C: drive, where hardcoding the file path is an acceptable answer. This application is mobile, and hardcoding the file path is not practical.

I am trying to import a text file via scanner, that contains a list of strings, 15 characters each, 1 per line. LOTS of lines. The file name is a.txt.

I call it using

File data = new File("a.txt");
Scanner in = new Scanner(data);

repeated the lines below with “b.txt”, using different Object names.

However, when I build the program, I get this error log (using Jcreator IDE):

--------------------Configuration: <Default>--------------------
E:\Simple Encryption\Simple_Encryption.java:17: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
    Scanner in = new Scanner(data);
                 ^
E:\Simple Encryption\Simple_Encryption.java:18: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
    Scanner numsIn = new Scanner(nums);
                     ^
2 errors

Process completed.

The program is in the folder E:/Simple Encryption/, which contains the following files and folders:

  • Simple_Encryption.java
  • Simple_Encryption.class
  • lock.png (unused)
  • a.txt
  • b.txt (same error as a.txt on import, just one line below)
  • /images (folder, contains icon.png)

There is nothing else in the folder. I cannot hardcode the file path because on different computers, it has different drive names, and will be distributed under different folders later. (Here (School), it’s on the E: drive, at home it’s the J:drive, and at work it’s on the G: drive.)

Although I have gotten help from existing errors, I need to import this on the program startup, and not just skip it. The file exists in it’s current form, and the program cannot function without it.

What is causing this error? And what can I do to prevent this?

  • 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-18T22:21:51+00:00Added an answer on June 18, 2026 at 10:21 pm
    E:\Simple Encryption\Simple_Encryption.java:17: unreported exception 
    java.io.FileNotFoundException; must be caught or declared to be thrown
    

    As your exception saying you need to use try- catch block

    try {
       Scanner numsIn = new Scanner(nums);
    catch (FileNotFoundException e) {
      // do something
    } finally {
      if (numsIn != null) numsIn .close();
    }
    

    OR

    you need to throw that exception though calling method

    public static void xxxx() throws FileNotFoundException {
       // do something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've gone through several similar questions, none seem to deal with this type of
There are a few similar questions, but nothing like this. How do you deal
Similar questions to this my have been asked a lot of times before. But
I see answers to similar questions and I'm sure I may just not be
I have read similar questions and their answers, however, it seems none deal with
I've seen a couple of similar questions here but I couldn't fix this problem.
I've checked for other questions relevant to this, but the only answer is Use
Other questions similar have been asked, but they didnt tend to deal with a
This might be a similar problem to my earlier two questions - see here
I guess this was asked before, but I could not find any similar question.

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.