Here you can find the source of writeFileFragment(FileChannel fc, long pos, ByteBuffer fragment)
public static boolean writeFileFragment(FileChannel fc, long pos, ByteBuffer fragment)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static boolean writeFileFragment(FileChannel fc, long pos, ByteBuffer fragment) { try {//from ww w . j a va2s .com fc.position(pos); int size = fragment.remaining(); if (fc.write(fragment) != size) return false; fc.force(false); } catch (IOException ex) { ex.printStackTrace(); return false; } return true; } }