Iveはinput = nextLine()を試して、Stringデータへの入力を追加しましたが、nullを返します。ここで何が起こる可能性がありますか?ファイルに書き込まれる出力がゼロなのはなぜですか?私のコードの問題は何ですか?
[withdrawメソッド]
public void Withdraw(){
System.out.print("Enter withdrawal amount:");
double withdraw = input.nextDouble();
System.out.println("Your withdrawal amount: " + withdraw);
if(this.balance - withdraw < 100){
System.out.println("The maintaining balance should not be less than 100. ");
}else
this.balance -= withdraw;
System.out.println("Your new balance is:" + this.balance);
}
[ファイルに追加]ここ
public void withdrawWriter(){
try{
String data = "Your withdrawal amount: " + withdraw;
File file = new File(this.name + ".txt");
//if file doesnt exists, then create it
if(!file.exists()){
file.createNewFile();
}
//true = append file
FileWriter fileWritter = new FileWriter(file.getName(),true);
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
bufferWritter.write("\r\n");
bufferWritter.write(data);
bufferWritter.close();
System.out.println("Done");
}catch(IOException e){
e.printStackTrace();
}
}
はスクリーンショットです: