在服务器端生成文件后,下载后并删除,改了后发现文件变成空白
public boolean getURLFile(HttpServletResponse res, String UrlString) {
try {
BufferedInputStream fis = new BufferedInputStream(new FileInputStream(new File(UrlString)));
ServletOutputStream out = res.getOutputStream();
byte[] buffer = new byte[2048];
int num;
while ((num = fis.read(buffer, 0, buffer.length)) != -1) {
out.write(buffer, 0, num);
}
fis.close();
out.close();
System.out.println( "get URL File done. ");
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
后来为了要下载后删除 我改成
public boolean getURLFile(HttpServletResponse res, String UrlString) {
try {
File file = new File(UrlString);
BufferedInputStream fis = new BufferedInputStream(new FileInputStream(file));
ServletOutputStream out = res.getOutputStream();
byte[] buffer = new byte[2048];
int num;
while ((num = fis.read(buffer, 0, buffer.length)) != -1) {
out.write(buffer, 0, num);
}
fis.close(); <