intellij-idea The system cannot find the file specified,

后端 未结 1 983
借酒劲吻你
借酒劲吻你 2021-01-22 07:22

can someone help me? i\'m pretty new to programming, I decided to give IDEA a try comming from eclipse and I have run into a problem I have imported a project from eclipse that

相关标签:
1条回答
  • 2021-01-22 07:42

    For a project structure like this:

    project
    |
    | -> src
    |    |
    |    | -> directory
    |    |    |
    |    |    | -> MyClass.java
    |    |    |
    |    |    | -> file.txt
    

    Use the below code to read the file in MyClass.java

    import java.io.*;
    
    class MyClass {
    
        public static void main(String... args) {
    
            try {
    
                BufferedReader br = new BufferedReader(new FileReader("src/directory/file.txt"));
    
                // read your file 
    
            } catch (FileNotFoundException e) {
    
                e.printStackTrace();
    
            } catch (IOException e) {
    
                e.printStackTrace();
    
            } catch (Exception e) {
    
                e.printStackTrace();
    
            }
    
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题