Name :Shreyal Mandot
Title : Assignment 5a2. Write a java programme to accept two file names as commandline arguments and copy containts of first to second in a manner that case of all alphabet is changed and digits are replaced by "*".Display appropriate error messages if first file does not exist.
import java.io.*;
class ass5a2
{
public static void main(String args[])throws IOException {
File f1;
char ch;int i=0;
f1=new File(args[0]);
if( ! f1.exists())
{
System.out.println(args[0]+" Does not Exist ! \n Programme Terminated......... ");
System.exit(0);
}
FileInputStream f1i=new FileInputStream(args[0]);
FileOutputStream f2o=new FileOutputStream(args[1]);
while(i != -1)
{
i=f1i.read();
ch=(char)i;
if(Character.isLetter(ch) )
{
if(!Character.isLowerCase(ch) )
{
ch=Character.toLowerCase(ch);
f2o.write(ch);
}
else
{
ch=Character.toUpperCase(ch);
f2o.write(ch);
}
}
if( Character.isDigit(ch) )
{
ch='*';
f2o.write(ch);
}
}
f1i.close();f2o.close();
}
}
No comments:
Post a Comment