我们的一个文件下载程序,代码如下,当文件本身又扩展名时,一切正常,就算更改扩展名保存也没事,问题是当是本来一个无扩展名文件时,下在画面的文件类型自动给选为文本类型,如果此时保存旧保存为XXX.txt,
如果不想保存成待扩展名文件,选保存成所有文件,这时问题更严重了,直接给保存成XXX..txt,还多加了一个点。
=================================================
try {
response.setContentType(ComConstant.CONTENT_TYPE);
response.setHeader(ComConstant.CONTENT_DISPOSTION, "attachment; filename=" + toUtf8String(reqFileName));
String downloadPath = getUploadPath(reqItemNo); ServletOutputStream out = response.getOutputStream();
//BufferedReader br = new BufferedReader(new FileReader(downloadPath + reqOrgFileName));
FileInputStream in = new FileInputStream(new File(downloadPath + reqOrgFileName));
byte[] bBuffer = new byte[2048];
int len;
while ( (len = in.read(bBuffer)) != -1) {
out.write(bBuffer,0,len);
}
out.close();
in.close();
}
catch (Exception e) {
logger.error("Exception:" + e);
}
如果不想保存成待扩展名文件,选保存成所有文件,这时问题更严重了,直接给保存成XXX..txt,还多加了一个点。
=================================================
try {
response.setContentType(ComConstant.CONTENT_TYPE);
response.setHeader(ComConstant.CONTENT_DISPOSTION, "attachment; filename=" + toUtf8String(reqFileName));
String downloadPath = getUploadPath(reqItemNo); ServletOutputStream out = response.getOutputStream();
//BufferedReader br = new BufferedReader(new FileReader(downloadPath + reqOrgFileName));
FileInputStream in = new FileInputStream(new File(downloadPath + reqOrgFileName));
byte[] bBuffer = new byte[2048];
int len;
while ( (len = in.read(bBuffer)) != -1) {
out.write(bBuffer,0,len);
}
out.close();
in.close();
}
catch (Exception e) {
logger.error("Exception:" + e);
}
response.setHeader(ComConstant.CONTENT_DISPOSTION, "attachment; filename=" + toUtf8String(reqFileName));
这句话中的reqFileName如果是中文可以么?
怎么样才能让它能保存为中文名称 呢?(例如:中文.doc)