0
的文件夾
嗨,我試圖將上傳的文件保存到我的項目中的文件夾,但我不知道如何給路徑。我還希望上傳文件的同名文件是存儲在文件夾中的文件的名稱。如何將上傳的文件保存到名稱爲
public void handleFileUpload(FileUploadEvent event) throws IOException {
LOG.info("Entered into save action event");
FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
String filename = event.getFile().getFileName();
UploadedFile file = event.getFile();
InputStream input = file.getInputstream();
OutputStream output = new FileOutputStream(new File("src/main/resources/uploads/schema.xsd", filename));
try {
IOUtils.copy(input, output);
} catch (IOException e){
LOG.error("Error in copying file.", e);
}
finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
}
的事情是我可以將它保存在桌面上,但我想它保存到eclps一個floder,這樣我可以在運行時訪問它,我有一個xsd該文件將從相同的位置導入另一個xsd文件。如果我試圖將它保存在桌面上或C:它不是導入。所以我想把xsd寫入一個文件夾。 – kish
你最近怎麼樣?在運行時從classpath加載文件將需要一個自定義類加載器。看看這個:http://stackoverflow.com/questions/60764/how-should-i-load-jars-dynamically-at-runtime – Aurasphere