Advertisement
NB52053

Console IN to Text OUT

Aug 12th, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. //// Input From console and Output at Text File. :)
  2.  
  3. public class File {
  4.  
  5.     public static void main(String args[]) throws IOException {
  6.         InputStreamReader cin = null;
  7.         FileWriter fr = new FileWriter("INPUT.txt",true);
  8.         PrintWriter pin = null;
  9.  
  10.         try {
  11.             cin = new InputStreamReader(System.in);
  12.             pin = new PrintWriter(fr,true);
  13.  
  14.             System.out.println("Enter characters, 'q' to quit.");
  15.             char c;
  16.             do {
  17.                 c = (char) cin.read();
  18.                 System.out.print(c);
  19.  
  20.                 pin.printf("%s", c);
  21.  
  22.             } while(c != 'q');
  23.  
  24.  
  25.  
  26.         }finally {
  27.             if (cin != null) {
  28.                 cin.close();
  29.                 pin.close();
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement