-5
我想在输入文件中搜索Student
s。以下是我迄今为止的工作概况。搜索文件中的学生
Class Student
,与setter方法,getter和显示方法(打印)
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); }
}
}
这种方法就什么都不显示了,我不知道为什么。你有什么见解吗?
你的输入文件是什么样的? – 2014-09-10 17:51:11
这段代码甚至不会编译。 – 2014-09-10 17:54:28
如果您创建一个最简单的示例,我们可以提供帮助。请参见[如何创建最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。 – DavidPostill 2014-09-10 19:09:39