如果我在 Windows 7 和 AIX(Unix 系统)上运行这个简单的程序,并使用 Winmerge 或 Compare It 等工具比较生成的两个文件,它会告诉我回车和换行不同但内容相同。
这是为什么?如果在这种情况下两者都使用相同的编码“UTF-8”,不应该是相同的吗?
如何使两个文件完全相等?
public class WriteFile {
public static void main(String[] args) throws IOException {
write();
}
public static void write() throws IOException {
File file = new File("/tmp/test.txt");
file.delete();
file.createNewFile();
String str = "hello";
FileOutputStream fileOs = new FileOutputStream(file);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(fileOs, "UTF-8"), true);
writer.println(str);
writer.close();
}
}