I am new to file handling. I tried reading a file using fileinputstream and file channel. I could not find out the bug in the following code. It runs successfully but file has not been transferred. New file is created with zero bytes. Please have a look at the code and check what went wrong
public class FileTest
{
public static void main(String[] args)
{
try {
File file = new File("sss.jpg");
FileChannel inChannel=new FileInputStream(file).getChannel();
//FileChannel inChannel = in.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(1024);
while(inChannel.read(buffer) > 0) {
FileChannel outChannel=new FileOutputStream("sss1.jpg",true).getChannel();
outChannel.write(buffer);
}
}
catch(IOException ex) {}
}
}