-1

I am new in this so I hope some one can help me I want to know How to take string input from user's in Java and save it to a txt. file ? (and please explain how if you can)

Dharmesh Rupani
  • 1,029
  • 2
  • 12
  • 22

1 Answers1

0

You can use Scanner and FileWriter:

Scanner s = new Scanner(System.in);
String text = s.nextLine();//read input from user
File f = new File("C:\\Users\\itama\\Desktop\\filename.txt");
try {
    FileWriter fw = new FileWriter(f);
    fw.write(text);
    fw.flush();
    fw.close();
} catch (IOException e) {
    e.printStackTrace();
}
ItamarG3
  • 4,092
  • 6
  • 31
  • 44