Answer to Question #320353 in Java | JSP | JSF for Shafa

Question #320353

Write a Java program to read first 3 lines from the file

1
Expert's answer
2022-03-29T11:40:21-0400


import java.io.*;


class App {


	public static void main(String[] args) {
		String fileName = "text.txt";


		String line = null;
		int i = 0;
		try {
			BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));
			while (((line = bufferedReader.readLine()) != null) && i < 3) {
				System.out.println(line);
				i++;
			}
			bufferedReader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS