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 a program in Java to demonstrate use of final class.

Write a java program to create 3 threads using Thread class. Three threads should calculate the sum of 1 to 5, 6 to 10 and 11to 15 respectively. After all thread finishes main thread should print the sum and average.

Write a program in Java to demonstrate single inheritance, multilevel inheritance and hierarchical inheritance.