hak*_*iko 1 java string java-io
我想用这段代码写一些东西但是在我运行之后,字符之间有空格.但在代码中我不给字符串空间.
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出是(在文本文件中): H e l l o W o r l d !
dos.writeBytes("Hello World!");
Run Code Online (Sandbox Code Playgroud)
从本质上讲,writeChars会将每个字符写为2个字节.你看到的第二个是额外的空间.
归档时间: |
|
查看次数: |
2199 次 |
最近记录: |