0% found this document useful (0 votes)
3 views4 pages

Java Exp3

The document outlines a Java program that creates a text file, allows user input to be saved in it, and then copies the content to another file. It includes code for file operations using File I/O streams, including reading from and writing to files. The program also handles exceptions and provides console output for user interaction.

Uploaded by

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

Java Exp3

The document outlines a Java program that creates a text file, allows user input to be saved in it, and then copies the content to another file. It includes code for file operations using File I/O streams, including reading from and writing to files. The program also handles exceptions and provides console output for user interaction.

Uploaded by

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

Name : Anamika Chauhan

PRN : 246109049

Batch : SB3

Expirement 3

Aim: To Create text file in File io stream: Display on console


Save input in file and use buffer to copy on other file

Code:
import [Link].*;

import [Link];

public class fileInOpStream {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

try {

File file1 = new File("[Link]");

File file2 = new File("[Link]");

[Link]("Enter text to store in file:");


String data = [Link]();

FileWriter fw = new FileWriter(file1);

BufferedWriter bw = new BufferedWriter(fw);

[Link](data);

[Link]();

[Link]("\nReading from file:");

FileReader fr = new FileReader(file1);

BufferedReader br = new BufferedReader(fr);

String line;

while((line = [Link]()) != null){

[Link](line);

[Link]();

BufferedReader br2 = new BufferedReader(new FileReader(file1));

BufferedWriter bw2 = new BufferedWriter(new FileWriter(file2));

while((line = [Link]()) != null){

[Link](line);

[Link]();

}
[Link]();

[Link]();

[Link]("\nData copied to [Link] successfully!");

} catch (Exception e) {

[Link]("Error: " + e);

[Link]();

Output

You might also like