public static void main(String[] args) throws FileNotFoundException {
@SuppressWarnings("unused")
Scanner in = new Scanner(System.in);
System.out.println("enter filename");
Filename=in.next();
PrintWriter outputFile =new PrintWriter(Filename);
outputFile.println();
outputFile.close();
getInput();
display();
}
public static void display() throws FileNotFoundException{
for (int i = 0; i < genders.length; i++) {
System.out.println(ages[i]+";"+genders[i]+";"+emails[i]+";"+salaries[i]);
}}
public static void getInput(){
System.out.print("How many users do you wish to enter: ");
int num = in.nextInt();
ages= new int[num];
genders = new String[num];
emails = new String[num];
salaries = new double[num];
for (int i = 0; i < num; i++) {
System.out.print("Please enter your age for person "+(i+1)+": ");
ages[i] = in.nextInt();
while (ages[i]<20 ||ages[i]>30){
System.out.println("invalid age please re enter again");
ages[i] = in.nextInt();}
in.nextLine();
嘿傢伙我試圖將用戶輸入的內容寫入文件。我的問題是它創建的文件,但沒有寫入它。我嘗試了各種方法,但沒有任何幫助?創建文件沒有寫入java
坦率地說,您的代碼有點混亂,但我仍然試圖查看您的代碼。別擔心,你沒有放棄。 – mashedpotats
重複的[http://stackoverflow.com/questions/18070629/how-to-read-from-users-input-in-java-and-write-it-to-a-file](http://stackoverflow .com/questions/18070629/how-to-read-from-users-input-in-java-and-write-it-to-a-file) – nihilon
代碼的哪個部分應該將用戶輸入寫入文件?您只能向文件寫入一行空白行,其他所有輸出都將寫入控制檯。 – Andreas