for (String name : filenames) {
FileInputStream in = new FileInputStream(input.readUTF());
int byteCounter = 0;
int rowCounter = 0;
long bufferCounter = 0;
byte[] b = new byte[8];
int read;
//in.skip(10);
//while((read = in.read()) != -1){
while((read = in.read(b, 0, 10)) != -1){
byteCounter ++;
if (byteCounter != 1000){
if (rowCounter == 16){
System.out.println("\n");
rowCounter = 0;
}
System.out.print(Integer.toHexString(read) + "\t");
bufferCounter ++;
rowCounter ++;
}else{
byteCounter = 0;
try{
Thread.sleep(200);
}catch(InterruptedException e) {
}
}
}
System.out.println("\n"+"================"+"\n");
}
Hi there, I was hoping someone might be able to help me with an issue I’ve been having. I’m trying to get my program to read in the first 10 bytes of a specified file. I can get it to work with the skip() but obviously this does the opposite of what I want (it removes the first 10 instead)
I’ve looked all over to no avail, if you can help me out, that’d be great.
You can probably see that I’ve tried to enter the read(b, off, len) into the code already but this just produces random characters as an output rather than the actual hex characters I want 74 65 71 etc (Edit: These random characters seem to be the hex code for the number of bytes read. So for a text file that has 23 hex chars in it, it produces a a 3 (or in other words: 10,10,3 = 23)
the problem is here
readcontains the number of bytes effectively read from stream. Teh bytes are in arrayb.By the way: your array has a size of 8. you should increas it to 10 if you want to read 10 bytes!