UPDATE FOR BINARY OUTPUT:
二進制輸出的更新:
// There are dependencies on how you create your floatbuffer for this to work
// I suggest starting with a byte buffer and using asFloatBuffer() when
// you need it as floats.
// ByteBuffer b = ByteBuffer.allocate(somesize);
// FloatBuffer fb = b.asFloatBuffer();
// There will also be endiance issues when you write binary since
// java is big-endian. You can adjust this with Buffer.order(...)
// b.order(ByteOrder.LITTLE_ENDIAN)
// If you're using a hex-editor you'll probably want little endian output
// since most consumer machines (unless you've got a sparc / old mac) are little
FileOutputStream fos = new FileOutputStream("some_binary_output_file_name");
FileChannel channel = fos.getChannel();
channel.write(byteBufferBackingYourFloatBuffer);
fos.close();
TEXT OUTPUT: Since you want this to be viewable I assume you want a text file. You'll want to use a PrintStream.
TEXT OUTPUT:由於您希望這是可見的,我假設您需要一個文本文件。你會想要使用PrintStream。
// Try-catch omitted for simplicity
PrintStream ps = new PrintStream("some_output_file.txt");
for(int i = 0; i < yourFloatBuffer.capacity(); i++)
{
// put each float on one line
// use printf to get fancy (decimal places, etc)
ps.println(yourFloagBuffer.get(i));
}
ps.close();
Didn't have time to post a full raw/binary (non-text) version of this. If you want to do that use a FileOutputStream, get the FileChannel, and directly write the FloatBuffer (since it's a ByteBuffer)
沒有時間發布完整的原始/二進制(非文本)版本。如果你想這樣做,請使用FileOutputStream,獲取FileChannel,並直接編寫FloatBuffer(因為它是一個ByteBuffer)