Q:

writing to a file using java.nio

I have to use java.nio to create a file of any desired size by populating it with data.  I am reading through a document, but am confused about when I need to flip, put, or write and am getting errors.  I have successfully done this program using .io but I am testing to see if .nio will make it run faster. 
This is my code so far.  args[0] is the size of the file you want to make and args[1] is the name of the file to be written to
public static void main(String[] args) throws IOException
 {
     nioOutput fp = new nioOutput();
     FileOutputStream fos = new FileOutputStream(args[1]);
     FileChannel fc = fos.getChannel();

     long sizeOfFile = fp.getFileSize(args[1]);      
     long desiredSizeOfFile = Long.parseLong(args[0]) * 1073741824; //1 Gigabyte = 1073741824 bytes      
     int byteLength = 1024;      
     ByteBuffer b = ByteBuffer.allocate(byteLength);

     while(sizeOfFile + byteLength < desiredSizeOfFile)
     {  
    // b.put((byte) byteLength);
     b.flip();
     fc.write(b);
     sizeOfFile += byteLength;       
     }
     int diff = (int) (desiredSizeOfFile - sizeOfFile);
     sizeOfFile += diff;

     fc.write(b, 0, diff);

     fos.close();
     System.out.println("Finished at " + sizeOfFile / 1073741824  + " Gigabyte(s)");                
 }

long getFileSize(String fileName) 
{
    File file = new File(fileName);        
    if (! file.exists() || ! file.isFile()) 
    {
        System.out.println("File does not exist");
        return -1;
    }
    return file.length();
}

A:

sorry everyone, I figured it out.  
 while(sizeOfFile + byteLength < desiredSizeOfFile)
     {           
     fc.write(b);
     b.rewind();
     sizeOfFile += byteLength;       
     }
     int diff = (int) (desiredSizeOfFile - sizeOfFile);
     sizeOfFile += diff;

     ByteBuffer d = ByteBuffer.allocate(diff);

     fc.write(d);
     b.rewind();

     fos.close();
     System.out.println("Finished at " + sizeOfFile / 1073741824  + " Gigabyte(s)");                
 }

