I have a text file where I need to check if there is a "1"
or a "0"
at a certain position. Note that it's the string representation of the numbers I'm checking. I've tried this:
RandomAccessFile dictionaryFile = new RandomAccessFile("path");
if("1".equals(new String(dictionaryFile.read()))){
// do stuff
}
but it results in:
ir/PersistentHashedIndex.java:322: error: no suitable constructor found for String(int)
while("1".equals(new String(dictionaryFile.read()))){
^
constructor String.String(String) is not applicable
(argument mismatch; int cannot be converted to String)
constructor String.String(char[]) is not applicable
(argument mismatch; int cannot be converted to char[])
constructor String.String(byte[]) is not applicable
(argument mismatch; int cannot be converted to byte[])
constructor String.String(StringBuffer) is not applicable
(argument mismatch; int cannot be converted to StringBuffer)
constructor String.String(StringBuilder) is not applicable
(argument mismatch; int cannot be converted to StringBuilder)
Seems to me like String
needs a byte array instead of just a byte to initialise a string. But I only want to give it one number. How can I achieve this? Can I maybe convert "1"
to its byte representation?
EDIT: Sorry about the comparison mistake, guys, I sorted it out. Same problem persists.