intellij-idea系统找不到指定的文件, [英] intellij-idea The system cannot find the file specified,

查看:837
本文介绍了intellij-idea系统找不到指定的文件,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我吗?我对编程还很陌生,所以我决定尝试从eclipse来的IDEA,但遇到了一个问题,我从eclipse导入了一个可以正常工作的项目,但是在IDEA中,我无法像在eclipse中一样引用res文件夹无法使用res/image.png我只能执行c:\ ect.有人知道为什么吗?我已将res文件夹设置为资源根.

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 works but in IDEA I cant referance my res folder like I do in eclipse like I cant use res/image.png I can only do c:\ect. anyone know why? I have set the res folder as a resource root.

推荐答案

对于这样的项目结构:

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

使用以下代码在MyClass.java中读取文件

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();

        }

    }

}

这篇关于intellij-idea系统找不到指定的文件,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆