I am already having a code which reads line by line.but i need to read only the first 3 lines out of 10 lines.
Code:
import java.io.*;
class FileRead1
{
public static void main(
String args[])
{
try{
FileInputStream fstream = new FileInputStream("myfile.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
System.out.println (strLine);
}
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}