Slip 18 - B) Write a java program to copy the data from one file into another file, while copying change the case of characters in target file and replaces all digits by ‘*’ symbol.

Solution :

import java.io.*;

class Slip18B{

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

        FileReader fr = new FileReader("a.txt");

        FileWriter fw = new FileWriter("b.txt");

        int c;

        while ((c=fr.read())!=-1){

          if(Character.isDigit(c)==false){

              if(Character.isUpperCase(c)){

                fw.write(Character.toLowerCase(c));

              }else if(Character.isLowerCase(c)){

                fw.write(Character.toUpperCase(c));

              }

          }else{

              fw.write('*');

          }

        }

        fr.close();

        fw.close();

    }

}

Output:

a.txt
Output_pic

b.txt
Output_pic



Post a Comment

0 Comments