0
我試圖使用以下代碼將映像文件從資源文件夾複製到本地系統。getResourceAsStream()在構建產品中不工作
InputStream inStream = null;
OutputStream outStream = null;
File bfile = new File(directoryPath + "/icons/" + outputFileName);
inStream = MyClass.class.getClassLoader().getResourceAsStream("/images/" + imgFileName);
try {
outStream = new FileOutputStream(bfile);
byte[] buffer = new byte[1024];
int length;
if (inStream != null && outStream != null) {
// copy the file content in bytes
while ((length = inStream.read(buffer)) > 0) {
outStream.write(buffer, 0, length);
}
inStream.close();
outStream.close();
}
System.out.println("File is copied successful!");
} catch (IOException e) {
e.printStackTrace();
}
當我運行eclipse時,這段代碼工作得很好。但是當我構建產品時,圖標不會被複制到本地系統。
我也試過
inStream = MyClass.class.getResourceAsStream("/images/" + imgFileName);
,但沒有運氣。
任何想法!