0
좋아, 그래서 나는 서브 클래스 '개'와 '새'추상적 인 '동물'클래스는 내가 읽고 바이너리에서 동물 개체의 알 수없는 번호로 프로그램을 작성할 필요가 있습니다 파일.이진 파일에서 객체의 임의의 수 읽기
public static void main(String[] args) throws FileNotFoundException {
readAnimals("birdsAndDogs.dat");
}
public static List<Animal> readAnimals(String filename) {
List<Animal> animals = new ArrayList<Animal>();
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(filename));
try {
while (true) {
Animal a =(Animal) ois.readObject();
if (a instanceof Animal)
animals.add((Animal)a);
System.out.println(a);
}
}
catch (EOFException eof) {
ois.close();
ois = null;
return animals;
}
}
catch (Exception e) {
return null;
}
}
}
이 바이너리 파일을 읽을 수 있으므로, 코드가 잘 모르겠어요 꽤 지저분 수 있습니다 쉽게 걸릴하려고 내 처음하지만 내 주요 문제는 내가 FileNotFoundExeption 점점 계속하지만 파일에 같은 패키지와 위치, 어떤 아이디어?
도 제대로 구조화 된 코드 그 자체이다? 응용 프로그램은 응용 프로그램에서 실행 된 디렉토리에있는 파일 이름을 찾습니다
new FileInputStream("justADog.dat")
을 볼 때 어떤 및 모든
덕분에
그들은 동일한 프로젝트 폴더에 있습니다. 또한 속성에서 전체 경로를 얻은 후에도 여전히 동일한 문제가 있습니다. – user2745043
@user 누구입니까? –
테스트하려고하는 이진 파일 및 모든 클래스 – user2745043