文件响应后删除文件 [英] Delete a file after a File response
本文介绍了文件响应后删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Resteasy放置请求后删除文件. 我的代码:
I want to delete a file after a Resteasy put request. My code:
@PUT
@Path("/audioconverter")
public File audioConverter(@Context HttpServletRequest request, File file,
@QueryParam("codec") String codec,....
...
return aFile();
}
返回后,我要在文件系统中删除aFile().我该怎么办?
After the return I want to delete aFile() in the filesystem. How can I do that?
推荐答案
遵循上面的一些建议,我能够执行以下操作:
Following some advice from above I was able to do the following:
File zipDirectory = new File(outputZipFolder);
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
java.nio.file.Path path = Paths.get(outputZipFile);
byte[] data = Files.readAllBytes(path);
output.write(data);
output.flush();
FileUtils.cleanDirectory(zipDirectory);
}
};
这篇关于文件响应后删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文