【发布时间】:2016-11-12 02:29:00
【问题描述】:
目前我正在尝试为我创建的 Java 游戏制作关卡编辑器。
我的问题是我的程序没有保存编辑过的关卡。
这是我目前制作的代码:
Path path = Paths.get(gameFile.getAbsolutePath());
FileSystem fs = FileSystems.newFileSystem(path, null);
Path p = fs.getPath("rpg"+fs.getSeparator()+"levels"+fs.getSeparator()+"level"+(short)level+".png");
OutputStream os = Files.newOutputStream(p);
ImageIO.write(img, "png", os);
os.close();
fs.close();
gameFile 是我游戏的 .jar 文件,其中包含关卡和
关卡保存为 .png 文件。
我试图将我的图片保存在 jar 之外并且它有效,所以我想我在文件系统或路径上犯了一个错误。
jar 中的 Path 是 rpg/levels/level*.png
编辑:
我变了
OutputStream os = Files.newOutputStream(p);
到
OutputStream os = Files.newOutputStream(p,StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING);
但现在关闭文件系统时出现错误
java.nio.file.FileSystemException: G:\RPG.jar: The process cannot access the file because it is being used by another process.
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
at sun.nio.fs.AbstractFileSystemProvider.delete(Unknown Source)
at java.nio.file.Files.delete(Unknown Source)
at com.sun.nio.zipfs.ZipFileSystem.sync(ZipFileSystem.java:1294)
at com.sun.nio.zipfs.ZipFileSystem.close(ZipFileSystem.java:277)
at de.jorolf.editor.LevelEditor$5.actionPerformed(LevelEditor.java:213)
【问题讨论】:
-
如果用户回答了您的问题,请同时接受他的回答 (Accepting Answers: How does it work?)。如果不是,请说明什么仍未得到答复,这是 StackOverflow 的一个非常重要的部分,非常感谢。