Iridium

## 字节流输出的二进制文件

1. 首先示范 Java 流工具和 Linux `xxd` 的使用： 代码片段
``````        FileOutputStream fos = new FileOutputStream("binary_output");
DataOutputStream dos = new DataOutputStream(fos);

dos.writeBoolean(false);
dos.close();
``````

``````\$ xxd -b binary_output
00000000: 00000000
``````

1. 再考察 `true` 的存储形式：
``````        dos.writeBoolean(true);
``````
``````\$ xxd -b binary_output
00000000: 00000001
``````

1. 继续考察其他：
``````        dos.write('\n');
``````
``````\$ xxd -b binary_output
00000000: 00001010                                               .
``````

``````        dos.writeInt(3);
``````
``````\$ xxd -b binary_output
00000000: 00000000 00000000 00000000 00000011
``````

``````        dos.writeDouble(3.14);
``````
``````\$ xxd -b binary_output
00000000: 01000000 00001001 00011110 10111000 01010001 11101011  @...Q.
00000006: 10000101 00011111
``````

1. `float`
``````        dos.writeFloat(3.14f);
``````
``````\$ xxd -b binary_output
00000000: 01000000 01001000 11110101 11000011
``````

1. 汉字
``````        dos.write('曹');
``````
``````\$ xxd -b binary_output
00000000: 11111001                                               .
``````

(11111001)<sub>2</sub> = (F9)<sub>16</sub> 这里不太理解，汉字`曹``UTF-8`编码是66F9，但这里只有後面两位，百思不得其解。TODO

1. 英文字母
``````        dos.write('A');
``````
``````\$ xxd -b binary_output
00000000: 01000001
``````

(01000001)<sub>2</sub> = (41)<sub>16<sub>，即字母`A``ASCII` 编码。

1. 以上综合输出
``````        dos.writeBoolean(true);
dos.write('\n');
dos.writeInt(3);
dos.writeDouble(3.14);
dos.writeFloat(3.14f);
dos.write('曹');
dos.write('A');
``````
``````\$ xxd -b binary_output
00000000: 00000001 00001010 00000000 00000000 00000000 00000011  ......
00000006: 01000000 00001001 00011110 10111000 01010001 11101011  @...Q.
0000000c: 10000101 00011111 01000000 01001000 11110101 11000011  ..@H..
00000012: 11111001 01000001                                      .A
``````

## 字符流产生的文本文件

``````true
33.143.14f曹A
``````
``````\$ xxd -b text.txt
00000000: 01110100 01110010 01110101 01100101 00001010 00110011  true.3
00000006: 00110011 00101110 00110001 00110100 00110011 00101110  3.143.
0000000c: 00110001 00110100 01100110 11100110 10011011 10111001  14f...
00000012: 01000001                                                                                                 A
``````

## 总结

### Iridium

Linux - 文件的分割(split)与合并(cat)

leonardos
2018/07/02
0
0
C&C++文件操作

流式文件操作 　　这种方式的文件操作有一个重要的结构FILE，FILE在stdio.h中定义如下以下是引用片段： 　　typedef struct { 　　int level; /* fill/empty level of buffer */ 　　uns...

2013/01/04
373
2

2018/04/19
0
0

huangbo929
2017/02/04
0
0
der pem cer crt key pfx等概念及区别

wushank
2018/06/29
0
0

winscp中使用sudo的方法

Linux就该这么学
25分钟前
1
0

yangjianzhou
31分钟前
1
0

56分钟前
3
0
DevSecOps 运维模式中的安全性

58分钟前
0
0
java 基础脑图 转载来的

NotFound403

3
0