Hi... I want to read only the first line of a file and print the line. I don't want to read the whole file. How can I do that ?
Here is how we normally read the file
import java.io.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Readfile {
public void Readfile(){
}
public static void main(String argv[]) throws Exception {
try {
BufferedReader br = new BufferedReader(new FileReader("inputfile.txt"));
String s=null;
while((s=br.readLine())!=null && (s = s.trim()).length() > 0){
String f[] = s.split("\t");
System.out.println(s);
} br.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(Readfile.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
So what should I do to make it stop reading the whole file and just print the first line of a text file ?
Thanks