我有做一個java命令的程序,我有一些代碼,但我不知道如何繼續我停留在一個地方,順便說一句,我想使命令有點問題/sendcash [username] [money] // how it looks like
製作輸入命令
我有驗證碼:
if (cmd.equals(AdminCommands[1])) {
String player = scanner.next();
int money = scanner.nextInt();
File folder = new File(player);
File pFile = new File(folder, player + ".txt");
File bFile = new File(folder, money + ".txt");
if (pFile.exists() && bFile.exists()) {
try {
Account pAcc = new Account(player, money);
if(pAcc.admin != 1) {
try {
writer = new BufferedWriter(new FileWriter(bFile));
writer.write(player);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
writer.close();
} catch (Exception e) {
}
}
LabelInfo.setText("Money transfer complited ! (" + money + ") to (" + pAcc.name + ")");
} else {
LabelInfo.setText("You can't transfer money to an admin!");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Username doesn't exist!");
}
}
}
編輯現在有了這個代碼沒有在控制檯中的文件太多我不知道這裏做什麼發生在類的代碼Account
public Account(String player, int cash) {
this.username = player;
this.money = cash;
}
但是,如果您能夠以相同的方式理解我:/ – user3390702
,那麼如何將金額轉入文件中,使用money文件初始化'BufferWriter',然後將錢串寫入它。編輯代碼 – Salah
查看 – user3390702