我想用这段代码写点东西,但是在我运行之后,字符之间有空白。但在代码中,我不给空间的字符串。java.io FileOutPutStream - 字符之间有空白。为什么?
import java.io.*;
public class WriteText{
public static void main(String[] args) {
FileOutputStream fos;
DataOutputStream dos;
try {
File file= new File("C:\\JavaWorks\\gui\\bin\\hakki\\out.txt");
fos = new FileOutputStream(file);
dos=new DataOutputStream(fos);
dos.writeChars("Hello World!");
}
catch (IOException e) {
e.printStackTrace();
}
}
}
输出是(以文本文件):H e l l o W o r l d !
我也是这样。仍然试图了解'writeChars'的用途是什么...... – PearsonArtPhoto
Java docs说:“将字符串s中的每个字符写入输出流,依次为每个字符两个字节,如果s为null,则NullPointerException为如果s.length为0,则不写入字符,否则首先写入字符s [0],然后写入s [1],依此类推;写入的最后一个字符是s [s.length-1] 。对于每个字符,实际上都是写入两个字节,首先是高位字节,与writeChar方法完全相同。“谁想要额外的一点。我认为很大的问题。 – hakiko
writeChars的目的是unicode支持。 – BevynQ