Friday, October 16, 2015

Program: Read from console and write everything to a file

import java.io.*;

class ConsoleRead{
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            FileWriter fw=new FileWriter("CreateFile.txt");
            String s1;
            while(!(s1=br.readLine()).equals("STOP")){
                fw.write(s1+"\r\n");
            
            }
            
            fw.close();
            br.close();
            
        }catch(IOException e){
            System.out.println("Exception occured");
        }
    }
}

No comments:

Post a Comment