Java ByteBuffer save to a File via FileChannel
import java.io.FileOutputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static void main(String[] argv) throws Exception { ByteBuffer bbuf = ByteBuffer.allocate(100); bbuf.put("demo2s.com".getBytes()); bbuf.rewind();//w w w. ja v a 2 s. c o m boolean append = true; FileChannel wChannel = new FileOutputStream("Main.java", append).getChannel(); wChannel.write(bbuf); wChannel.close(); } }