Here you can find the source of readAndTransfer(final String dir)
public static void readAndTransfer(final String dir)
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.SocketChannel; public class Main { public static void readAndTransfer(final String dir) { File file = new File(dir); try (FileInputStream fis = new FileInputStream(file)) { FileChannel fc = fis.getChannel(); ByteBuffer bb = ByteBuffer.allocate(1024); SocketChannel sc = null; while (fc.read(bb) != -1) { }//w w w. j a v a2 s .co m } catch (Exception e) { e.printStackTrace(); } } }