BCA Slip13 Java

Java

Slip13

Q.1) Write a java program to copy the contents of one file into the another file, while copying change the case of alphabets and replace all the digits by ‘*’ in target file. [Marks 30] 

Solution

import java.io.*;

class Replace
{
    public static void main(String args[])
    {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
        try
        {
        System.out.print("Enter name of source file : ");
        String file1 = br.readLine();
        System.out.print("Enter name of target file : ");
        String file2 = br.readLine();
       
            FileInputStream f1;
            FileOutputStream f2;
            int c;
            f1 = new FileInputStream(file1);
            f2 = new FileOutputStream(file2);
            while((c=f1.read())!=-1)
            {
                if(Character.isDigit(c))
                   c = '*'; 
                    else if(Character.isUpperCase((char)c))
                        c = Character.toLowerCase((char)c);
                    else if(Character.isLowerCase((char)c))
                        c = Character.toUpperCase((char)c);
                    f2.write((char)c);
             }
             System.out.println("\n\tContents have been written");
             f1.close();
             f2.close();         
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }
}





BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post