.datファイルの読み取りに問題があります。現在、私は.dat / .txtファイルの読み方を知っていますが、これは私にとって少し注意が必要です。
だから私はこのようなデータのセットを持っています:
test.dat
Sunday
Scuba Diving Classes
Mr.Jones
N/A
Yes
Sunday
Sailing
Mr. Jackson
N/A
Yes
Sunday
Generation Next
Ms.Steele
N/A
Yes
Monday
Helping Hands
Ms.Wafa
ANX0
No
このファイルで行う必要があるのは、ファイルをレコードごとに調べることです。文字列activitynameがアクティビティの名前(例:スキューバダイビングクラス)と等しい場合、 Cで始まる変数が表示用に設定されます。そのためのコーディングは次のとおりです。
try{
BufferedReader reader = new BufferedReader(new FileReader("test.dat"));
int numberOfLines = readLines();
numberOfLines = numberOfLines / 6;
for(int i=0;i < numberOfLines; i++)
{
String CDay = reader.readLine();
String CActivityName = reader.readLine();
String CSupervisor = reader.readLine();
String CLocation = reader.readLine();
String CPaid = reader.readLine();
String nothing = reader.readLine();
if(CActivityName.equals(activityName))
{
txtDay.setText(CDay);
txtSupervisor.setText(CSupervisor);
txtLocation.setText(CLocation);
//If it Activity is paid, then it is shown as paid via radiobutton
if(CPaid.equals("Yes"))
{
radioYes.setSelected(rootPaneCheckingEnabled);
}
if(CPaid.equals("No"))
{
radioNo.setSelected(rootPaneCheckingEnabled);
}
}
else
{
reader.close();
}
}
}
catch(IOException e)
{
Logger.getLogger(AddActivity.class.getName()).log(Level.SEVERE, null, e);
}
}
numberoflines変数を使用してファイルを調べましたが、ロジックに欠陥があり、これをどのように処理するかわかりません。
メソッドの現在のステータスとエラー
現在、このメソッドは最初のレコードのスキューバダイビングクラスのみを読み取り、if条件がfalseの場合はファイル全体を調べません。
ヘルプ!