我想将文件的编码形式更改为另一个(不管哪个)。但是,当我打开带有结果的文件(文件 w.txt)时,里面就乱了。Windows 不理解它正确。
我应该输入什么结果编码(args [1]),这样它才能被 Windows 记事本正确解释?
import java.io.*;
import java.nio.charset.Charset;
public class Kodowanie {
public static void main(String[] args) throws IOException {
args = new String[2];
args[0] = "plik.txt";
args[1] = "ISO8859_2";
String linia, s = "";
File f = new File(args[0]), f1 = new File("w.txt");
FileInputStream fis = new FileInputStream(f);
InputStreamReader isr = new InputStreamReader(fis,
Charset.forName("UTF-8"));
BufferedReader in = new BufferedReader(isr);
FileOutputStream fos = new FileOutputStream(f1);
OutputStreamWriter osw = new OutputStreamWriter(fos,
Charset.forName(args[1]));
BufferedWriter out = new BufferedWriter(osw);
while ((linia = in.readLine()) != null) {
out.write(linia);
out.newLine();
}
out.close();
in.close();
}
}
输入:
Ala
ma
Kota
输出:
?Ala
ma
Kota
为什么有一个'?