我在服务器中有一个文件。A.xls. 客户希望它被加密。所以我做了。新文件名为 B.xls。当我使用 HttpServletResponse 流下载 B.xls 时,结果让我感到困惑。因为下载的文件大小与 B.xls 不同。
A.xls 大小为 3kb。B.xls 大小为 6kb。但是下载的文件大小是5kb。
请给我一个提示来解决这个问题。提前致谢。
///////////////////////////////////////////
///// this is my code. ////////////////////
File file = new File(tempDir+filename);
FileOutputStream fos = new FileOutputStream( file );
byte[] readBuff = new byte[4096];
int readLen = -1;
try {
while( ( readLen = is.read( readBuff ) ) != -1 ) {
fos.write( readBuff, 0, readLen );
}
fos.flush();
} finally {
if( fos != null ) {
try {fos.close();} catch( IOException e ) { e.printStackTrace(); }
}
}
//## Encrypt the target File ##
// Do - Something
// the new file name is enc_filename
outputStream = response.getOutputStream();
File encFile = new File(tempDir+enc_filename);
System.out.println("enc file size :" + encFile.length());
outputStream = response.getOutputStream();
inputStream = new FileInputStream( encFile );
readLen = -1;
while( ( readLen = inputStream.read() ) != -1 ) {
outputStream.write(readLen);
}
outputStream.flush();
......
close stream code....
......