Leer ultima liena de un fichero
Publicado por Chema (2 intervenciones) el 21/02/2007 11:41:59
Hola, necesito leer la ultima linea de un fichero para extraer una parte final, pero con mi código lo ultimo que saca es el null de final de fichero. ¿Podéis echarme una mano?
Gracias
public static String readLastLine(String localPath) throws IOException {
File file = new File(localPath + "history.cvs");
String lastLine = null;
if (file.exists()) {
String linea;
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
while ((br.readLine()) != null) {
linea = br.readLine();
}
fr.close();
} else {
System.out.println("No found file: \"history.cvs\"");
System.exit(1);
}
return lastLine;
}
Chema
Gracias
public static String readLastLine(String localPath) throws IOException {
File file = new File(localPath + "history.cvs");
String lastLine = null;
if (file.exists()) {
String linea;
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
while ((br.readLine()) != null) {
linea = br.readLine();
}
fr.close();
} else {
System.out.println("No found file: \"history.cvs\"");
System.exit(1);
}
return lastLine;
}
Chema
Valora esta pregunta


0