[英]Java Eclipse - I don't see “Android Application” when I select File/New
[英]When I create a file through code I can't see it in eclipse
所以我在java做一個游戲引擎,它有兩部分:編輯器和游戲引擎本身。 在編輯器中,我序列化 Scene 對象並將它們寫入 .scene 文件以供引擎讀取,但該文件未顯示在 eclipse 中,我可以在文件資源管理器中看到它,因此創建了它。 有一段時間我沒有注意,因為我仍然可以使用File
class 讀取文件。但后來我嘗試將其導出到可運行的 jar 文件中,但構建沒有成功,所以我嘗試使用getClass().getResource("path")
,我遇到了問題,據我所知,由於一些奇怪的原因,文件沒有被添加到構建路徑中,即使它在 src 文件夾中,我可以通過編程方式將文件添加到構建路徑中,還是我需要做點別的?
這是一些代碼:
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;
}
}
讀取.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;
}
}
提前致謝
您很可能需要刷新項目,以便 Eclipse 看到新文件已添加。 Select 項目並按 F5。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.