I am a long time eclipse user and I have started to play around with IntelliJ IDEA.
So from my understanding, a project in IntelliJ is the same as the Eclipse worksp
Instructions
File myFile = new File("./resources/images/newfile.txt");
u need to specify complete path inside quotes something like this-->
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Application {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("E:\\coding\\ProcessingFiles\\src\\myfile.txt");
Scanner input = new Scanner(file);
while (input.hasNextLine()){
String line = input.nextLine();
System.out.println(line);
}
input.close();
}
}
Run
> Edit Configurations
Configuration
tab
Working directory
: Your file path is relative to this.Hope this help!
Use the full path of the file instead.
Right click on your file in your project, select "Copy Path", and paste that in to the path of your file.
EDIT: You could also use a relative path for your file. If your file is located in resources/
, then you could use the form ./resources/yourfile.txt
.
├── resources
│ └── test123.txt
└── src
├── MainClass.java
Yesterday I met the same trouble as you.
change the setting of IDEA. run->Edit Configurations -> (select your Application at left window.then set the input content named "Working directory" at right window)
Just move the file directly to the project folder which calls Java (and something under the blue-blurred stripe you made :P).
If that doesn't help, then move the test123.txt
file to FirstJavaProgram
directory.
You can also change filename to one of these:
src/test123.txt
FirstJavaProgram/src/test123.txt
I am not sure which one will be fine in your case.