简体   繁体   English

当我通过代码创建文件时,我在 eclipse 中看不到它

[英]When I create a file through code I can't see it in eclipse

So I'm making a game engine in java, it has two parts: the editor and the game engine itself.所以我在java做一个游戏引擎,它有两部分:编辑器和游戏引擎本身。 In the editor I serialize Scene objects and write them into.scene files for the engine to read, but the file doesn't show up in eclipse, I can see it in the file explorer so it is created.在编辑器中,我序列化 Scene 对象并将它们写入 .scene 文件以供引擎读取,但该文件未显示在 eclipse 中,我可以在文件资源管理器中看到它,因此创建了它。 for a while I didn't pay attention because I can still read the file using the File class. But then I tried exporting it into a runnable jar file and the build didn't work, so I tried using getClass().getResource("path") and I ran into issues, as I understand the file is not being added to the build path for some weird reason even thou it's in the src folder, can I add the file to the build path programmatically or do I need to do something else?有一段时间我没有注意,因为我仍然可以使用File class 读取文件。但后来我尝试将其导出到可运行的 jar 文件中,但构建没有成功,所以我尝试使用getClass().getResource("path") ,我遇到了问题,据我所知,由于一些奇怪的原因,文件没有被添加到构建路径中,即使它在 src 文件夹中,我可以通过编程方式将文件添加到构建路径中,还是我需要做点别的?

Here is some code:这是一些代码:

public File createSceneFile(String path) {
    try {
        File file = new File(path);
        
        if(file.createNewFile()) {
            FileOutputStream fileStream = new FileOutputStream(path);
            ObjectOutputStream os = new ObjectOutputStream(fileStream);
            os.writeObject(scene);
            os.close();
        }
            
        return file;
    }catch(IOException e) {
        e.printStackTrace();
        return null;
    }
}
    
public File updateScene(String path) {
    try {
        FileOutputStream fileStream = new FileOutputStream(path);
        ObjectOutputStream os = new ObjectOutputStream(fileStream);
        os.writeObject(scene);
        os.close();
        
        return new File(path);
    }catch(IOException e) {
        e.printStackTrace();
        return null;
    }
}

Code to read the.scene files:读取.scene文件的代码:

public Scene getScene(URL url) {
    try {
        InputStream inStream = url.openStream();
        ObjectInputStream ois = new ObjectInputStream(inStream);
        Scene s = null;
        try {
            s = (Scene)ois.readObject();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        ois.close();
        
        s.instantiation = this;
        return s;
    }catch(IOException e) {
        e.printStackTrace();
        return null;
    }
}

Thanks in advance提前致谢

Most likely you need to refresh the project so that Eclipse sees that the new file has been added.您很可能需要刷新项目,以便 Eclipse 看到新文件已添加。 Select the project and hit F5. Select 项目并按 F5。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM