2014-09-10 2 views
-5

Student s에 대한 입력 파일을 검색하고 싶습니다. 지금까지 내 작품의 개요가 있습니다. 세터, 게터 및 표시 방법 (인쇄)와 학생을 파일로 검색

Class Student

,

Class StudentFile

import java.io.*; 
import java.util.ArrayList; 
public class StudentFile { 

public void Trouver(int id) 
    { 
     try 
     { 
     File file = new File("C:/Users/Akram/Documents/akram.txt"); 
     BufferedReader read = new BufferedReader(new FileReader(file)); 
     String str; 
     while((str=read.readLine())!=null) 
     { 
      Student s; 

      if(s.getId()==id) 
       System.out.println(s.print()); 
     } 
     read.close(); 
      } 
     catch(IOException e) { System.out.println(e); } 
    } 
} 

이 방법 디스플레이 아무것도, 나는 이유를 모르겠어요. 통찰력있어?

+0

입력 파일의 모양은 무엇입니까 ?? –

+0

이 코드는 컴파일되지 않습니다. –

+0

최소한의 예를 만들면 도와 드리겠습니다. [최소한의 완전하고 검증 가능한 예제를 만드는 방법] (http://stackoverflow.com/help/mcve)를 참조하십시오. – DavidPostill

답변

1

파일에서 행을 읽고 내용을 str에 할당하고 있지만이 값으로는 아무 것도하지 않습니다.

또한 Student은 비어있는 것 같습니다.

BufferedReader read = new BufferedReader(new FileReader(file)); 
    String str; 
    while((str=read.readLine())!=null) 
    { 
     // Your constructor assigns str to ID property of Student 
     // Casting to Integer, because ID is a number 
     Student s = new Student(Integer.valueOf(str)); 

     if(s.getId()==id) 
      System.out.println(s.print()); 
    } 

는 또한 학생에 print() 방법은 정말 당신이 원하는 출력을 확인하십시오

이 파일을 치죠하는 것은 학생의 ID를 포함합니다.

관련 문제