Java program to read a text file and displays it's contents on screen.

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ReadTextFile {
    public static void main(String[] args) {
        String filePath = "yourFileName.txt"; // Replace with the actual file path and name

        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            System.err.println("Error reading the file: " + e.getMessage());
        }
    }
}

Comments

Popular posts from this blog

What is a Web Browser? वेब ब्राउज़र क्या है?

Java's Support System जावा का सहयोगी तंत्र

The Internet and Java इंटरनेट और जावा का सम्बन्ध