无法使用 servler 下载 .txt 文件中的泰文字符。当我点击下载时,泰文字符在文件中显示为??? 生成的文件格式为 UNIX,文件类型为 ANSI。但我需要生成正确的 THAI 字符以及正确的文件格式,即 Windows 和 ANSI。
请注意,我已经使用了所有可能的字符编码组合。下面是我用来下载文件的代码。
在此先感谢,任何帮助appriciated。
ftp=new FTPClient();
ftp = Utilities.getFTPConnection(ftpServerIP, ftpUserName, ftpPassword);
retValue = ftp.changeWorkingDirectory(uploadRoot);
Value = ftp.retrieveFile(fileName, new FileOutputStream( downloadFile ));
if (!Value)
{
throw new Exception ("Downloading of remote file "+downloadFile.getName()+" failed. ftp.retrieveFile() returned false.");
}
isSuccess = true;
}
}
catch(Exception e)
{
}
finally
{
Connection Close Code
downloadFile.exists();
}
InputStream in = null;
PrintWriter printWriter = null;
DataInputStream dataInputStream = null;
BufferedReader bufferReaderFile = null;
String strLineFromFile;
try
{
File f= new File(uploadPath+File.separator+clientCode+File.separator+fileName);
if(f.exists())
{
result=Action.SUCCESS;
response.reset();
response.setCharacterEncoding("US-ASCII");
response.setContentType("application/x-download");
response.setHeader("Cache-Control", "max-age=0");
response.setHeader("Content-Disposition","attachment;filename="+ fileName);
in = new FileInputStream(f);
dataInputStream = new DataInputStream(in);
bufferReaderFile = new BufferedReader(new InputStreamReader(dataInputStream,"US-ASCII"));
printWriter=response.getWriter();
byte[] buf = new byte[8192];
int sizeRead = 0;
while ((sizeRead = in.read(buf, 0, buf.length)) > 0)
{
outStream.write(buf,0,sizeRead);
}
while ((strLineFromFile = bufferReaderFile.readLine()) != null)
{
printWriter.println(strLineFromFile);
outStream.print("\n\r");
}
printWriter.flush();
printWriter.close();
bufferReaderFile.close();
dataInputStream.close();
in.close();