I have a scanner that's trying to read a file named info.data in the src folder.I get Exception in thread "main" java.io.FileNotFoundException: info.data (The system cannot find the file specified). What's the address I should put in the scanner?
When you create an API project, it is set up as a Java project with separate folders for source and class files. The source folder is named src . It contains the Java code of the application. A few Java classes are also created together with the new project.
Right-click on the main project folder, then select "New," then "Other." Select "Other" from the file selection window, then select "Folder." Give your folder a name and click "Finish."
userdir is the directory where NetBeans stores user configuration data such as window layouts, editor settings, menu and toolbar customizations and various module settings. Per default, it is a (hidden) directory called . netbeans stored in the user's home directory.
To open a local file/folder (as a file-explorer) in Netbeans, in the top menu-bar goto: Window -> Favourites (or press Ctrl+3), this will open 'Favourites' pane, here you can open files or folders (in Linux, by default you will see your 'home' directory).
If the input file is always part of your application (i.e. you also put this into the .jar file later) you should use getResourceAsStream()
in order to read its contents.
InputStream in = getClass().getResourceAsStream(filename);
Scanner scanner = new Scanner(in);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With