您的位置:首页 > 编程语言 > Java开发

Java创建一个临时文件方法

2015-06-10 15:35 531 查看
public File save(byte[] data) {
OutputStream stream = null;

try {
File tmpFile = File.createTempFile("screenshot", ".png");
tmpFile.deleteOnExit();

stream = new FileOutputStream(tmpFile);
stream.write(data);

return tmpFile;
} catch (IOException e) {
throw new WebDriverException(e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
// Nothing sane to do
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java tempfile 临时文件