|
Simple Sand Samples |
Java > バイナリデータをファイルへ書き込む
write-bin.java
import java.io.*;
class Test {
public static void main(String args[]) {
try {
FileOutputStream fo = new FileOutputStream("hoge.bin");
fo.write(1);
fo.write(2);
fo.write(3);
fo.close();
} catch (Exception e) {
System.out.println("例外" + e + "発生!!");
}
System.out.println();
}
}
$ javac read_bin.java
$ java Test hoge.bin
$ od -tx1 hoge.bin
0000000 01 02 03
0000003
$
$ java Test hoge.bin
$ od -tx1 hoge.bin
0000000 01 02 03
0000003
$