Monday, 10 March 2025

Write a java program to display ASCII values of the characters from a file.

 

import java.io.FileReader;

import java.io.IOException;


public class AsciiFileReader {

    public static void main(String[] args) {

     String fileName = "input.txt"; // Change to your file name


        try (FileReader reader = new FileReader(fileName))

          {

            int character;

            while ((character = reader.read()) != -1)

             { // Read until end of file

 System.out.println("Character: " + (char) character + " ASCII: " + character);

            }

        } catch (IOException e) {

            System.out.println("Error reading file: " + e.getMessage());

        }

    }

}