FTP サーバーからファイルを取得しています。ファイルはUTF-8としてエンコードされています
ftpClient.connect(props.getFtpHost(), props.getFtpPort());
ftpClient.login(props.getUsername(), props.getPassword());
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
inputStream = ftpClient.retrieveFileStream(fileNameBuilder
.toString());
そして、別の場所で入力ストリームを読んでいます
bufferedReader = new BufferedReader(new InputStreamReader(
inputStream, "UTF-8"));
しかし、ファイルは UTF-8 エンコードとして読み取られません!
試しftpClient.setAutodetectUTF8(true);
ましたが、まだ動作しません。
何か案は?
編集: たとえば、元のファイルの行は ...00248090041KENAN SARÐIN 00000000015.993FAC... です。
FTPClient 経由でダウンロードした後、それを解析して Java オブジェクトにロードします。Java オブジェクトのフィールドの 1 つは name で、この行では「KENAN SAR�IN」として読み取られます。
ディスクに直接ダンプしようとしました:
File file = new File("D:/testencoding/downloaded-file.txt");
FileOutputStream fop = new FileOutputStream(file);
ftpClient.retrieveFile(fileName, fop);
if (!file.exists()) {
file.createNewFile();
}
2 つのファイル (FTP サーバーのファイルとディスクにダンプされたファイル) の MD5 チェックサムを比較したところ、同じでした。