StreamCorruptedException what?
It's throwing this error at the code with orange text
employees is an array list of Employee objects
Code:
public void displayFileContents(){
File[] files = directory.listFiles();
File chosenDirectory = new File(files[chooseFile(directory.list(), files) - 1].getPath());
try {
FileInputStream fileIn = new FileInputStream(chosenDirectory);
ObjectInputStream objectIn = new ObjectInputStream(fileIn);
while(fileIn.available() > 0){
try {
[COLOR="DarkOrange"]employees.add((Employee) objectIn.readObject());[/COLOR]
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
System.out.println("Error while reading object");
}
}
objectIn.close();
for(int i = 0; i < employees.size(); i++){
System.out.println(employees.get(i).toString());
}
} catch (IOException e) {
System.out.println("Error in displayFileContent");
e.printStackTrace();
}
}
The "Choose file" method
Code:
public int chooseFile(String[] fileNames, File[] files){
int i = 0, choice = 1, counter = fileNames.length;
while (counter > 0){
System.out.println("[" + choice + "]" + fileNames[i]);
choice++;
i++;
counter--;
}
return getInput(1, fileNames.length);
}