까지 다음 줄을 얻는 것은 그래서 이것은 내가 지금까지 무엇을 가지고 :텍스트 파일 내부에서 문자열을 찾는 방법. 그런 다음 특정 한도
public String[] findStudentInfo(String studentNumber) {
Student student = new Student();
Scanner scanner = new Scanner("Student.txt");
// Find the line that contains student Id
// If not found keep on going through the file
// If it finds it stop
// Call parseStudentInfoFromLine get the number of courses
// Create an array (lines) of size of the number of courses plus one
// assign the line that the student Id was found to the first index value of the array
//assign each next line to the following index of the array up to the amount of classes - 1
// return string array
}
내가 파일 내가 찾으려고 노력하고있는 문자열을 포함하는 경우 찾는 방법을 알고 있지만 나도 몰라 그 전체 라인을 검색하는 방법
이것은 처음 게시하는 것입니다. 잘못된 것이 있다면 알려주세요.
File file = new File("Student.txt");
try {
Scanner scanner = new Scanner(file);
//now read the file line by line...
int lineNum = 0;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
lineNum++;
if(<some condition is met for the line>) {
System.out.println("ho hum, i found it on line " +lineNum);
}
}
} catch(FileNotFoundException e) {
//handle this
}
이 숙제 인 경우, 같은 태그되어야한다 : 여기 –
입력 파일의 샘플을 추가 할 수 있습니까? – RonK