10)Write a Java program to create 2 files F1 and F2.Copy the contents of file F1 by changing the case into file F2.F2 = F1 Also copy the contents of F1 and F2 in F3.F3 = F1+F2 Display the contents of F3.Use Command Line Arguments.


import java.io.*;
class TwoFileCopyInOne
{
public static void main(String args[])throws IOException
{
FileInputStream f1;
FileOutputStream f3;
RandomAccessFile f2;
int c;

f1=new FileInputStream(args[0]);
f2=new RandomAccessFile(args[1],”rw”);
while((c=f1.read())!=-1)
{
if(Character.isUpperCase((char)c))
{
c=Character.toLowerCase((char)c);
f2.write((char)c);
}
else
if(Character.isLowerCase((char)c))
{
c=Character.toUpperCase((char)c);
f2.write((char)c);
}
else
f2.write((char)c);
}
f1.close();
f2.close();

f1=new FileInputStream(args[0]);
f2=new RandomAccessFile(args[1],”rw”);
f3=new FileOutputStream(args[2]);
while((c=f1.read())!=-1)
{
f3.write((char)c);
System.out.print((char)c);
}
while((c=f2.read())!=-1)
{
f3.write((char)c);
System.out.print((char)c);
}
}
}

>java TwoFileCopyInOne f1.txt t2.txt t3.txt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s