Note that there are some explanatory texts on larger screens.

plurals
  1. POFileNotFoundException while file exists in same folder as program
    primarykey
    data
    text
    <p>Similar questions deal with files on the <code>C:</code> drive, where hardcoding the file path is an acceptable answer. This application is mobile, and hardcoding the file path is not practical.</p> <p>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 <code>a.txt</code>.</p> <p>I call it using</p> <pre><code>File data = new File("a.txt"); Scanner in = new Scanner(data); </code></pre> <p>repeated the lines below with "b.txt", using different Object names.</p> <p>However, when I build the program, I get this error log (using Jcreator IDE):</p> <pre><code>--------------------Configuration: &lt;Default&gt;-------------------- 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. </code></pre> <p>The program is in the folder <code>E:/Simple Encryption/</code>, which contains the following files and folders:</p> <ul> <li>Simple_Encryption.java</li> <li>Simple_Encryption.class</li> <li>lock.png (unused)</li> <li>a.txt</li> <li>b.txt (same error as <code>a.txt</code> on import, just one line below)</li> <li>/images (folder, contains icon.png)</li> </ul> <p>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 <code>E:</code> drive, at home it's the <code>J:</code>drive, and at work it's on the <code>G:</code> drive.)</p> <p>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.</p> <p>What is causing this error? And what can I do to prevent this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload