0
無法使用servler將THAI字符下載到.txt文件中。 當我點擊下載THAI字符在文件中顯示爲???生成的文件格式是UNIX,而FILE Type是ANSI。但是我需要生成適當的THAI字符以及適當的文件格式,即Windows和ANSI。無法通過servlet下載.TXT文件中的泰文字符
請注意,我已經使用了字符編碼的所有可能組合。 下面是我用來下載文件的代碼。
在此先感謝,任何幫助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();
編碼必須是UTF-8。其次,它是如何使用任何ftp-client手動下載的 –