Write a program to copy contents of file 'abc.txt' to 'xyz.txt'

From Exception, Stream and I/O chapter in PU/ Programming in Java

Asked on 2 Feb, 2021

Like 0 Dislike 430 Views

Add a comment

1 Answers

arjun adhikari on 2 Feb, 2021 Like 0 Dislike

import java.io.* ;


class ReadingAndWriting {
    public static void main(String[] agrs)throws IOException{
        FileInputStream fi = new FileInputStream("abc.txt") ;
        FileOutputStream fo = new FileOutputStream("xyz.txt") ;
        int readByte = 0 ;
        while(true){
            readByte = fi.read() ;
            if(readByte == -1) break ;
            fo.write(readByte) ;
        }
        System.out.println("Copied") ;
    }
}

Add a comment


Add your answer