0% found this document useful (0 votes)
2 views1 page

Console Reading Writing Files Java

The document provides an overview of console reading and writing, as well as file handling in Java. It covers common classes used for reading and writing from the console and files, along with example code snippets. Important points include the necessity of closing streams and handling exceptions properly.

Uploaded by

Naveen Sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Console Reading Writing Files Java

The document provides an overview of console reading and writing, as well as file handling in Java. It covers common classes used for reading and writing from the console and files, along with example code snippets. Important points include the necessity of closing streams and handling exceptions properly.

Uploaded by

Naveen Sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Console Reading and Writing & File Handling in Java

1. Console Reading in Java:


- Reading input from the user through keyboard.
- Common classes: Scanner, BufferedReader, Console.

Example:
Scanner sc = new Scanner([Link]);
String name = [Link]();
[Link]("Hello " + name);

2. Console Writing in Java:


- Writing output on the screen using [Link]() or println().

Example:
[Link]("Welcome to Java!");

3. File Reading in Java:


- Reading data from a file.
- Common classes: FileReader, BufferedReader, Scanner.

Example:
FileReader fr = new FileReader("[Link]");
BufferedReader br = new BufferedReader(fr);
String line;
while ((line = [Link]()) != null) {
[Link](line);
}
[Link]();

4. File Writing in Java:


- Writing data into a file.
- Common classes: FileWriter, BufferedWriter, PrintWriter.

Example:
FileWriter fw = new FileWriter("[Link]");
[Link]("Hello Java File Writing!");
[Link]();

Important Points:
- Input → From keyboard or file
- Output → To screen or file
- Always close streams after use
- Use try-catch or throws IOException for error handling

You might also like