使用createTempFile產生暫存檔
windows systems 預設檔案位置:
C:\Users\USER\AppData\Local\Temp
UNIX systems 預設檔案位置 :
"/tmp" or "/var/tmp"
private File tempFile;
public void createFile(InputStream is) throws IOException {
tempFile = File.createTempFile("tempFile", ".scv");
OutputStream os = new FileOutputStream(tempFile);
int n;
byte[] buffer = new byte[1024];
while ((n = is.read(buffer)) > -1) {
os.write(buffer, 0, n); // Don't allow any extra bytes to creep in,
// final write
}
os.close();
}
其它文章