C
Craig
java.io.FileInputStream zipStream = new java.io.FileInputStream
(path);
File file=new File(path);
System.out.println(file.length());
FileChannel fc= zipStream.getChannel();
ByteBuffer buffer=ByteBuffer.allocate((int)file.length());
buffer.clear();
System.out.println(buffer.capacity());
fc.read(buffer);
fc.close();
zipStream.close();
byte[] b=new byte[buffer.capacity()];
System.out.println(b.length);
buffer.get(b,0,b.length);
return b;
I am getting a BufferUnderflowException when I do buffer.get(b);
I don't know why this is wrong because all the three print statements
gives the same value: 9932
The second question I have is,how can I avoid int casting when I do
bytebuffer.allocate. I am concerned about handling larger files.
Kindly Reply.
Thanks,
Craig
(path);
File file=new File(path);
System.out.println(file.length());
FileChannel fc= zipStream.getChannel();
ByteBuffer buffer=ByteBuffer.allocate((int)file.length());
buffer.clear();
System.out.println(buffer.capacity());
fc.read(buffer);
fc.close();
zipStream.close();
byte[] b=new byte[buffer.capacity()];
System.out.println(b.length);
buffer.get(b,0,b.length);
return b;
I am getting a BufferUnderflowException when I do buffer.get(b);
I don't know why this is wrong because all the three print statements
gives the same value: 9932
The second question I have is,how can I avoid int casting when I do
bytebuffer.allocate. I am concerned about handling larger files.
Kindly Reply.
Thanks,
Craig