Java BufferedWriter write user console input to file

Description

Java BufferedWriter write user console input to file

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStream;

public class Main {
  public static void main(String[] args) throws Exception {
    System.out.println("type something:");
    InputStream in = System.in;
    BufferedWriter bw = new BufferedWriter(new FileWriter("Main.txt"));

    int letter;//from  w ww  .  java2 s  .c  o  m

    while ((letter = in.read()) != -1) {
      bw.write((char) letter);
      bw.flush();
    }
  }
}



PreviousNext

Related