Are you sure the file exists and you have read access? It is odd that you are creating the parent directory before reading. Check your logcat for the stacktrace. Also, make sure you declared the "android.permission.WRITE_EXTERNAL_STORAGE" permission in your AndroidManifest.
I wrote the following method real quick. Should work fine for you.
java
public static String[] tail(File file, int tail) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
List<String> lines = new ArrayList<>();
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
lines.add(line);
}
reader.close();
return lines.subList(Math.max(0, lines.size() - tail), lines.size()).toArray(new String[tail]);
}
Example usage:
java
try {
File gps = new File(Environment.getExternalStorageDirectory(), "GPS/gps.txt");
String[] lastFourLines = tail(gps, 4);
} catch (IOException e) {
// Are you sure the file exists?
// Did you declare "android.permission.WRITE_EXTERNAL_STORAGE" permission?
}