私は自分のコードを最初に置きます:
@Post
public Representation post(InputStream zip) throws Throwable {
createFile(zip, "C:/temp");
return new StringRepresentation("File uploaded");
}
public void createFilee(InputStream zipStream, uploadedFileLocation) throws Exception {
try {
writeToFile(zipStream, uploadedFileLocation);
FileUtils.forceDelete(new File(uploadedFileLocation));
} catch (Exception e) {
throw e;
}
}
private void writeToFile(InputStream uploadedInputStream, String uploadedFileLocation) {
try {
OutputStream out = new FileOutputStream(new File(uploadedFileLocation));
int read = 0;
byte[] bytes = new byte[1024];
out = new FileOutputStream(new File(uploadedFileLocation));
while ((read = uploadedInputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.flush();
out.close();
uploadedInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
ファイルをサーバーに送信すると、ファイルが削除されません。を使用FileUtils.forceDelete()
すると、ファイルを削除できないと表示されます。ファイルユーティリティを使用してファイルを削除しようとした後、サーバーがまだ実行されている間にファイルを手動で削除できます。なぜそれ自体を削除できないのですか?! 何か案は?ありがとう
編集:問題InputStream
は、POST が返されるまで、POST からのが生きているということでしょうか? それで、ファイルを削除するために呼び出しても、ストリームは POST によってまだ生き続けていますか? これは可能ですか?