Friday 5 February 2016

TO SAVE THE OUTPUT OF A PROGRAM TO SAVE VOWELS IN A FILE IN THE HARD DISK.

/* Hi people , we have run java programs but as soon as we finish running with the programs we cannot store our results;


 *  consequently they get deleted;
 *  Now through 'File Handling' we can actually save our output! 
 *  Here is a simple program on File Handling,
 */ 
import java.util.*;// importing java.util package
import java.io.*;// importing java.io package
class vowels
{
    void main() throws IOException
    {
        int ch = 0;
        Scanner in = new Scanner(System.in);
        System.out.println("Enter String");
        String st = in.nextLine();// Taking input through scanner class
        FileWriter fw = new FileWriter("v.dat");// creating another file named- v.dat
        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter pw = new PrintWriter(bw);
       
        String str = "AEIOUaeiou";
        for(int i = 0 ;i<st.length();i++) //To write all the vowels in v.dat
        {
            ch = 0;
            for(int j = 0 ;j<str.length();j++)
            if(str.charAt(j)==st.charAt(i))
            {
                ch =1 ;
                break;
            }
            if(ch==1)
            pw.println(st.charAt(i));// the function that we use to write vowels
        }
        pw.close();
        bw.close();
        fw.close();//closing the writer
         FileReader fr = new FileReader("v.dat");
        BufferedReader br = new BufferedReader(fr);
        String sl = br.readLine();
        while(sl!=null) // so that it stops as soon as the reader looks at a null string
        {
            System.out.println(sl);// To print all the files
            sl = br.readLine();
        }
        br.close();
        fr.close();// closing the reader
    }
}
in the file : you can see the extention
    

1 comment:

  1. Michael Anderson8 February 2016 at 01:43

    I really like your concepts. I hope you'll also work on the program I've e-mailed you.
    Thanks.

    ReplyDelete