READ IN JAVA

Maha

READ IN JAVA

The Reader class of the java.io package is an abstract superclass that represents a stream of characters. 

In order to create a Reader, we must import the java.io.Reader package first. Once we import the package, here is how we can create the reader.

Java read input you can use the Scanner class from the java.util package. An example that demonstrate the various ways to read input in Java.


Syntax:

// Creates a Reader

Reader input = new FileReader();


Example:

import java.io.*;

import java.util.*;

class Readfile 

{

public static void main(String[] args)

{

try 

{

String str = "Readfile";

Reader reader = new StringReader(str);

int ch;

ch = reader.read();

System.out.println("\nInteger value " + "of character read: " + ch);

System.out.println("Actual" + "character read: " + (char)ch);

reader.close();

}

catch (Exception e) 

{

System.out.println(e);

}

}

}

Output:

Integer value of character read: 82

Actualcharacter read: R



Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send