tags:

views:

45

answers:

1

I have this code..


String you = buf.readLine(); Log.d("STRING", ikaw); StringTokenizer st = new StringTokenizer(you); double lat = Double.parseDouble(st.nextToken()); double lng = Double.parseDouble(st.nextToken()); int type = Integer.parseInt(st.nextToken()); String text = st.nextToken(); Log.d("File Reading stuff", "success = " + lat); Log.d("File Reading stuff", "success = " + lng); Log.d("File Reading stuff", "success = " + type); Log.d("File Reading stuff", "success = " + text);

How am i suppose to test if it is already the end of file? I don't know how many lines there are in my file and I need to print all of them. I know i should place my code inside a while loop, but I have no idea how to get the end of file.

+1  A: 

I assume the code you have listed is inside a loop, and I assume buf is an instance of BufferedReader. You just need to check for null after you call readLine(). It returns null when you've hit the end of the file.

mbaird
indeed. i'd throw in that instead of doing a `for` loop, it's rather customary to do a `while` that includes the nullcheck: `String you; while ((you = buf.readLine()) != null) { ... }`
David Hedlund
ayt! got it already. haha stupid me. thanks! :)
lulala