|
-
Jan 14th, 2007, 08:55 PM
#1
Thread Starter
Junior Member
[RESOLVED]HELP!!Retrieving binary data using Scanner
Code:
int counter=0;
Scanner input = new Scanner(new FileReader("/home/huiling/my-cdk/bin.bin"));
while(input.hasNextBoolean()==true)
{
counter++;
for(int j=0;j<1024;j++)
{
boolean bit = input.nextBoolean();
}
System.out.println(counter);
}
The result is 0 for the counter, but i have binary in my file, does anyone knows why it returns 0? But it works alright when i use FileInputStream and ObjectInputStream. This means my file isn't corrupted or something.
Or is ther anyway where I can count the number of binaries in a file?
Last edited by huiling25; Jan 15th, 2007 at 01:43 AM.
-
Jan 15th, 2007, 01:41 AM
#2
Thread Starter
Junior Member
Re: HELP!!Retrieving binary data using Scanner
I have found a solution to counting the number of binaries in the file by using another method.
Code:
int i=0;counter=0;
BitSet fingerprint = new BitSet();
try{
FileInputStream input = new FileInputStream ("/home/huiling/my-cdk/bin.bin");
ObjectInputStream binData = new ObjectInputStream (input);
while(i>=0)
{
counter++;
for(int j=0;j<1024;j++)
{
boolean bit =binData.readBoolean();
fingerprint.set(j,bit);
}
}
System.out.println(counter);
binData.close();
}//try
catch (EOFException eof)
{
System.out.println("End of File.");
}
catch (FileNotFoundException fe)
{
System.out.println("No such file.");
}
Last edited by huiling25; Jan 15th, 2007 at 01:45 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|