.dat 파일을 읽는 데 문제가 있습니다. 현재 .dat/.txt 파일을 읽는 방법을 알고 있지만이 파일은 다소 까다 롭습니다. 그래서줄 단위로 파일을 반복합니다.
이 같은 데이터의 집합이 있습니다
내가이 파일로해야 할 것은 기록에 의해 파일 레코드를 통해 이동하는 것입니다
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
TEST.DAT을하고있는 경우 문자열 activityname. 활동 이름 (예 : 스쿠버 다이빙 클래스)과 같음 으로 시작하는 변수는으로 설정됩니다. 여기에 대한 코드입니다 : 내가 파일을 통해 이동합니다 numberoflines 변수를 사용했습니다
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);
}
}
,하지만 내 논리는 결함이, 내가 어떻게
현재 상태를 통해 이동하는 생각이없고,
방법의 오류는 현재이 방법은 첫 번째 기록 스쿠버 다이빙 수업을 읽고, 만약 조건이 거짓 일 때 전체 파일을 통과하지 않습니다.
도움말!
: 것을 시도하지 않은 이름이 activityName과 같지 않은 활동을 만 v 고 즉시 독자를 닫습니다. 하지마. –
그게 효과가! 내 논리 결함을 보지 못했습니다 감사합니다! – Geuni