FileReading.java
23 linesjava
DOWNLOAD
1// Aim: Program to perform File Handling operations (File Reading).
2import java.io.FileReader;
3
4import java.util.*;
5
6public class FileReading{
7    public static void main(String[] args) {
8        Scanner s = new Scanner(System.in);
9        System.out.print("eneter file name with .txt: ");
10        String filePath = s.nextLine();
11        try {
12            FileReader fileReader = new FileReader(filePath);
13            int character;
14            while ((character = fileReader.read()) != -1) {
15                System.out.print((char) character);
16            }
17            fileReader.close();
18        } catch (Exception e) {
19            System.out.println("An error occurred while reading the file: " + e.getMessage());
20        }
21        s.close();
22    }
23}