ASCII のヘッダーとバイナリの値を使用して、ファイルを書き込む必要があります。
今のところ、私はこれを使用しています:
File file = new File("~/myfile");
FileOutputStream out = new FileOutputStream(file);
// Write in ASCII
out.write(("This is a header\n").getBytes());
// Write a byte[] is quite easy
byte[] buffer = new buffer[4];
out.write(buffer, 0, 4);
// Write an int in binary gets complicated
out.write(ByteBuffer.allocate(4).putInt(6).array());
//Write a float in binary gets even more complicated
out.write(ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN)
.putFloat(4.5).array());
問題は、実際に ASCII で値を書き込むよりも、その方法で書き込むのが (パフォーマンスの点で) 非常に遅いことです。しかし、私はより少ないデータを書いているので、それはより短いはずです。
私は他のJavaクラスを見てきましたが、それらはASCII書き込み専用か、バイナリ書き込み専用のようです。
この問題について他に何か提案はありますか?