【问题标题】:intellij-idea The system cannot find the file specified,intellij-idea 系统找不到指定的文件,
【发布时间】:2015-03-14 23:34:10
【问题描述】:

有人可以帮助我吗?我对编程很陌生,我决定从 Eclipse 中尝试一下 IDEA,我遇到了一个问题我已经从 Eclipse 导入了一个可以工作的项目,但是在 IDEA 中我不能像在 Eclipse 中那样引用我的 res 文件夹,就像我一样不能使用 res/image.png 我只能做 c:\ect。有谁知道为什么?我已将 res 文件夹设置为资源根目录。

【问题讨论】:

  • 我刚刚发现我还需要将项目添加到路径中,所以我需要使用 myproject/res/image.png 而不是 res/image.png,它可以工作,但我就像我习惯只使用 res/image.png 一样,有什么办法可以解决这个问题吗?
  • 如果您正在为 android 编写代码,请使用 Android Studio。有一个用于导入 eclipse 项目的向导,它对我来说效果很好。
  • 不,它不是针对 android 的,它是一个常规的 java 程序,对于意外的 android 标签感到抱歉。
  • 嘿,如果你把图片放在源码根目录下,编译并通过“classloader”getResourceAsStream(...)访问它们,这可能是解决你问题的一种方法
  • 不,那没用,好的,这是我的项目层次结构:首先是(to my classes)myProject> src/main/java(the source root)/com.glen.game,然后(对我的资源)myProject>src/main/res(the source root),然后在我的代码中我必须使用texture = TextureLoader.getTexture("PNG", new FileInputStream("myproject/src/main/res/" + fileName+ ".PNG"));,然后在eclipse 我通常使用texture = TextureLoader.getTexture("PNG", new FileInputStream("res/" + fileName+ ".PNG")); 并且在 eclipse 中有效,但在 IDEA 中无效

标签: java eclipse intellij-idea


【解决方案1】:

对于这样的项目结构:

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

使用以下代码读取 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();

        }

    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-21
    • 2023-03-17
    • 2017-12-21
    • 2015-09-28
    • 2015-11-08
    • 2018-08-26
    • 2019-01-20
    相关资源
    最近更新 更多