I am trying to copy large files over a network using sockets and channels. Here is a code snippet
//sender side
FileInputStream in = new FileInputStream(inputFileName);
FileChannel fromFile = in.getChannel();
SocketChannel toSocket = sendSocket.getChannel();
fromFile.transferTo(0, 999999, toSocket );
However, in the line where I call transferTo I get NullPointerException. Any idea why? (I also enclosed it in a while loop as I've been advised, but that's just for robustness and doesn't treat that problem)