How to read file in Java? (BufferedReader Example)

Java provides many API to read files , here is once simple example to read a file using Buffered Reader

package com.pretech;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class BufferedReaderExample {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new FileReader("c://buffertext.txt"));
		String value;
		while ((value = bf.readLine()) != null) {
			System.out.println(value);
		}
	}
}

No comments:

Post a Comment

12 classic String-based Java interview questions with simple explanations and code.

  1️⃣ Check if a String is a Palindrome Problem Given a string, check if it reads the same forward and backward. Example: "madam...

Featured Posts