R
Renli
How can I efficiently (!) and fast search a file for a given hex value (e.g. x'6A')
resp. how can I count the number of occurencies in a given hex value ?
Ulf
The following info should help.
You can make a FileInputStream like this:
FileInputStream fis = new FileInputStream("filename.ext");
You can read in a byte from the file like this:
int value = fis.read(); // if value == -1, it's the end of the file.
You can translate an integer into a hex string like this:
String hexstr = Integer.toHexString(value);
You can translate a hex string into an integer like this:
int value = Integer.valueOf(hexstring, 16);
(or)
int value = Integer.parseInt(hexstring, 16);
-----
There, now you know how to read a byte in from a file; how to detect
EOF, and how to convert both the hex code you're looking for and/or
the int you read into the same format for an equality test. Remember
that if you convert both into a string use .equals() and not == to
determine if they are the same.
Good luck and let us know how it works out.
-