这是我正在使用的代码,当我运行它并打开输出文件时,我看到Hello world已保存。
为什么会这样?
public class Fileoutputstream {
public static void main(String [] args) throws IOException {
File file = null;
FileOutputStream fileOut = null;
try {
file = new File("output");
if (!file.exists()) {
file.createNewFile();
}
fileOut = new FileOutputStream(file, true);
String textToSave = "Hello World";
byte[] textToSaveBytes = textToSave.getBytes();
fileOut.write(textToSaveBytes);
fileOut.close();
} catch (Exception e) {
}
}
}
答案 0 :(得分:0)
您写入文件的字节实际上是ASCII代码字符串,因此毫无疑问您的输出文件是文本文件。 大多数程序会将文件视为' text'如果其中没有非文本字符,即NULL字节,控制字符等。