Reading files with Intellij idea IDE

后端 未结 7 725
野的像风
野的像风 2020-12-14 00:51

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

相关标签:
7条回答
  • 2020-12-14 01:39

    Instructions

    1. Simply right-click on your project directory (the very top folder), then select "New > Directory". Specify a name such as "resources".

    1. (optional) Once the folder is generated then right-click "resources" directory, then select "New > Directory" and create an "images" directory.
    2. Drag-and-drop your image file into the "images" or "resources" folder you just created. Reference your newly added project file with code File myFile = new File("./resources/images/newfile.txt");
    0 讨论(0)
  • 2020-12-14 01:39
    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();
    
        }
    }
    
    0 讨论(0)
  • 2020-12-14 01:42
    1. Run > Edit Configurations
    2. Under Configuration tab
      • Working directory: Your file path is relative to this.

    Hope this help!

    0 讨论(0)
  • 2020-12-14 01:45

    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
    
    0 讨论(0)
  • 2020-12-14 01:46

    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)

    0 讨论(0)
  • 2020-12-14 01:47

    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:

    1. src/test123.txt

    2. FirstJavaProgram/src/test123.txt

    I am not sure which one will be fine in your case.

    0 讨论(0)
提交回复
热议问题