次のコードを使用して、大きなテキストファイルを行単位で処理しています。問題は、正確には英語、クロアチア語以外の言語を使用していることです。多くの文字は出力ファイルにappearとして表示されます。どうすれば解決できますか?新しいファイルに保存すると、奇妙な文字が出力されるBufferedWriter
ファイルはANSIですが、これはInputStreamReaderと互換性のあるエンコーディングタイプではないようです。元のファイルをどのようなエンコードタイプで保存する必要がありますか?
try (BufferedWriter bw = new BufferedWriter(new FileWriter(FILENAME))) {
String line;
try {
try (
InputStream fis = new FileInputStream("C:\\Users\\marti\\Documents\\Software Projects\\Java Projects\\TwitterAutoBot\\src\\main\\resources\\EH.Txt"); InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8")); BufferedReader br = new BufferedReader(isr);
) {
while ((line = br.readLine()) != null) {
// Deal with the line
String content = line.substring(line.lastIndexOf(" ") + 1);
System.out.println(content);
bw.write("\n\n" + content);
}
}
} catch (IOException e) {
e.printStackTrace();
}
// bw.close();
} catch (IOException e) {
e.printStackTrace();
}
入力ファイルはどのようなエンコーディングを使用していますか? –
@GregKopff ANSIです。 – santafebound
@MartinErlicもし 'ANSI'ならあなたのコードに*なぜ*' UTF-8' **を指定しましたか? --- [ANSI](https://en.wikipedia.org/wiki/ANSI_character_set)の場合、[拡張ANSI](https://en.wikipedia.org/wiki/Extended_ASCII)のフレーバーはどれですか?それ? – Andreas