使用Java将用户输入写入文本文件

时间:2016-06-07 12:08:06

标签: java input java.util.scanner

我正在尝试将用户输入写入文本文件。以下是我的尝试。我无法弄清楚这有什么问题。

public class Source {

    public static void main(String[] args) throws IOException {

       Scanner Scanner = new Scanner(System.in);
       String fileName = "write.txt";
       FileWriter FileWriter = new FileWriter(fileName);
       BufferedWriter bufferedWriter = new BufferedWriter(FileWriter);

       System.out.println("Give an input to write to txt file");
       String input = Scanner.next();

       while(input != null){
         input = Scanner.next();
         System.out.println(input);    

         //bufferedWriter.write(input);
         //bufferedWriter.close();     
    }
   }
}

0 个答案:

没有答案