I have the following code, where I'm counting the lines in a file. And I also want to retrieve the very last line (which is integer) :
try {
byte[] c = new byte[1024];
int count = 0;
int readChars = 0;
boolean empty = true;
while ( (readChars = is.read(c)) != -1) {
for (int i = 0; i < readChars; ++i){
if (c[i] == '\n'){
++count;
empty = true;
lastLine = c[i].intValue();
} else {
empty = false;
}
}
}
if (!empty) {
count++;
}
System.out.println("the last line was " + lastLine);
return count;
I added this line - lastLine = c[i].intValue();
But this gives the error :
C:\Java_Scratch>javac ParentClass2.java ParentClass2.java:90: byte cannot be dereferenced lastLine = c[i].intValue();
How do I convert the byte to int ?