Write a program in Java to perform I/O operations on a Text file.

 AIM: Write a program in Java to perform I/O operations on a Text file.

CODE:

import java.io.File;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import  java.io.IOException;

public class p33

{

            public static void main(String args[]) throws IOException

            {

                        File source=new File("E:/java_happy/hello.txt");

                        File dest=new File("E:/java_happy/demo1.txt");

                       

                        FileInputStream FIS = new FileInputStream(source);

                        FileOutputStream FOS = new FileOutputStream(dest);

                       

                        int ch = FIS.read();

                                    while(ch!=-1)

                                    {

                                                System.out.print((char)ch);

                                                FOS.write(ch);

                                                ch = FIS.read();

                                    }

                       

                        FIS.close();

                        FOS.close();

            }

}

OUTPUT:





Comments

Popular posts from this blog

Write an application that illustrates method overriding in the same package and different packages. Also demonstrate accessibility rules in inside and outside packages

Describe abstract class called Shape which has three subclasses say Triangle, Rectangle, and Circle. Define one method area()in the abstract class and override this area() in these three subclasses to calculate for specific object.

Write a program that illustrates interface inheritance. Interface P12 inherits from both P1 and P2. Each interface declares one constant and one method. The class Q implements P12. Instantiate Q and invoke each of its methods. Each method displays one of the constants.