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)
-
3Have you tried anything?ItamarG3– ItamarG32016-11-30 17:14:20 +00:00Commented Nov 30, 2016 at 17:14
-
1there are plenty of examples of this on stackoverflow, just go to the top right and enter the title of your problem in that search barRAZ_Muh_Taz– RAZ_Muh_Taz2016-11-30 17:17:07 +00:00Commented Nov 30, 2016 at 17:17
-
Please make a minimal working example : stackoverflow.com/help/mcveLdiCO– LdiCO2016-11-30 17:21:13 +00:00Commented Nov 30, 2016 at 17:21
Add a comment
|
1 Answer
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();
}
1 Comment
ItamarG3
@SaadAL-awad then you should accept the answer. (V under answer score)