我正在尝试将项目中的资源复制到磁盘上的另一个位置。到目前为止,我的代码是这样的:
if (!file.exists()){
try {
file.createNewFile();
Files.copy(new InputSupplier<InputStream>() {
public InputStream getInput() throws IOException {
return Main.class.getResourceAsStream("/" + name);
}
}, file);
} catch (IOException e) {
file = null;
return null;
}
}
它能正常运行,但是InputSupplier
类已被废弃,因此我想知道有没有更好的方法来实现我所需的功能。