こんにちは皆さん、私は Java を初めて使用します。私の要件の 1 つは、ユーザーが、従業員、住所、性別、ステータス、勤務日数、1 日あたりの料金などの編集削除ビュー レコードを追加できるようにするプログラムを作成することです。メモ帳 、それを追加した後、プログラムは税金やsssの貢献などを計算し、別のtxtfileに保存され、表示および編集することもできます. 私の問題は、txtfileに計算を書き込めず、「FileNotFoundException」を取得できないことです。txtファイルを読み書きする私のコードはこちら
public static void payrollReadFromFile(String filename) {
// initializes br identifer as BufferedReader.
BufferedReader br = null;
payrolls.clear(); // removes all elements in arraylist employees
try {
// instantiate br as FileReader with filename param
br = new BufferedReader(new FileReader(filename));
try {
String name;
double gincome, nincome, deduc, sss, pagibig, phil = 0; // initialize identifiers
// reads each line through br identifier, and stores it on
// temporary identifiers
// loop continues until null is encountered
while ((name = br.readLine()) != null) {
gincome = Double.parseDouble(br.readLine());
sss = Double.parseDouble(br.readLine());
pagibig = Double.parseDouble(br.readLine());
phil = Double.parseDouble(br.readLine());
deduc = Double.parseDouble(br.readLine());
nincome = Double.parseDouble(br.readLine());
// adds the data to employees arraylist
payrolls.add(new Person( name, gincome, sss, pagibig, phil,deduc, nincome));
}
} finally {
br.close(); // closes BufferedReader
}
} catch (IOException e) {
e.printStackTrace();
}
}
// method which writes data into parameter 'filename'
// uses PrintWriter and FileWriter
public static boolean payrollWriteToFile(String filename) {
boolean saved = false;
PrintWriter pw = null; // pw is a PrintWriter identifier
try {
// instantiate pw as PrintWriter, FileWriter
pw = new PrintWriter(new FileWriter(filename));
try {
// for each loop. each data from employees is written to parameter
// filename
for (Person payroll : payrolls) {
// pw.println(employee.getId());
pw.println(payroll.getName());
pw.println(payroll.getGincome());
pw.println(payroll.getSss());
pw.println(payroll.getPagibig());
pw.println(payroll.getPhil());
pw.println(payroll.getDeduc());
pw.println(payroll.getNincome());
}
saved = true;
} finally {
pw.close();
}
} catch (IOException e) {
e.printStackTrace();
}
return saved;
}
誰かが私を助けることができますか?どうすればいいのかわからない。前もって感謝します