[英]How to write user input on file then retrieve it back
I have done do the code below for take 5 user input and print it out . 我已经完成了下面的代码,需要5个用户输入并将其打印出来。 Now i wanna to take the input from users and save it on to file, and retrieve it back . 现在,我想从用户那里获取输入并将其保存到文件中,并取回。 Pleas i need to explain who i can do this . 请我解释一下谁可以做。
Thanks and regards 谢谢并恭祝安康
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class user_info {
public static void main(String[] args) throws Exception {
int i;
String Uname;
int UIDnum;
user_input[] input = new user_input[5];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (i = 0; i < input.length; i++) {
input[i] = new user_input();
int number = i + 1;
System.out.println("User:" + number);
System.out.println("Please Enter your name:");
Uname = br.readLine();
input[i].setName(Uname);
System.out.println("Please Enter your ID number:");
UIDnum = Integer.parseInt(br.readLine());
input[i].setIDnum(UIDnum);
}
//char n = (char)UIDnum;
//String u = Integer.toString(UIDnum);
for (i = 0; i < input.length; i++) {
System.out.println("your name:" + input[i].getName());
System.out.println("your ID number:" + input[i].getIDnum());
}
}
}
Possibly you can have a look at the specified below link: 可能您可以查看下面指定的链接:
https://www.caveofprogramming.com/java/java-file-reading-and-writing-files-in-java.html https://www.caveofprogramming.com/java/java-file-reading-and-writing-files-in-java.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.