import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.*; class Main{ public static void main(String args[]){ Scanner scan = new Scanner(System.in); System.out.println("Name: "); String name = scan.next(); System.out.println("Age: "); int age = scan.nextInt(); System.out.println("Name:" + " " + name + " " + "Age:" + " " + age); scan.close(); try{ File file = new File("userAge.txt"); PrintWriter writer = new PrintWriter(file); writer.write(name + " " + age); writer.close(); } catch(IOException e){ e.printStackTrace(); } } }
try(FileWriter fw = new FileWriter("userAge.txt", true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw)) { out.println(name + " " + age); } catch (IOException e) { //exception handling left as an exercise for the reader }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)