我真的不知道问题出在哪里。
我想将这些字符打印到一个文本文件中,然后使用printWriter来执行相同的操作。
如果文件有一个“;”,我想用一个新行代替它,这就是我在做什么,
public static void downloadFile_txt(String sourceFilePathName, String contentType, String destFileName, HttpServletResponse response) throws IOException, ServletException
{
File file = new File(sourceFilePathName);
//FileInputStream fileIn = new FileInputStream(file);
FileReader fileIn = new FileReader(file);
long fileLen = file.length();
response.setContentType(contentType);
response.setContentLength((int)fileLen);
response.setHeader("Content-Disposition", String.valueOf((new StringBuffer("attachment;")).append("filename=").append(destFileName)));
PrintWriter pw = response.getWriter();
// Loop to read and write bytes.
int c=-1;
while ((c = fileIn.read()) != -1)
{
if(c!=59)
{
pw.print((char)c);
}
else
{
pw.println();
}
}
pw.flush();
pw=null;
fileIn.close();
}但是除了最后一个字符外,我的文件正在为所有内容激怒。
Eg.input =
:00004000,FFAD,2 Byte Ch;
:0000FFBD,FFBE,2 Byte Ch;
:0000FFBF,FFFF,2 Byte Ch;输出即时通讯
:00004000,FFAD,2 Byte Ch
:0000FFBD,FFBE,2 Byte Ch
:0000FFBF,FFFF,2 Byte C最后的“h”没有被打印。
提前致谢