I store over 40,000 objects into a text file. My problem is reading all objects from text file is too slow. It even takes 4349 ms for 1,000 objects-text file.
This is reading objects from text file.
long startR = System.currentTimeMillis();
try{
ois = new ObjectInputStream(new FileInputStream(f));
code_from_file.clear();
Codes obj = new Codes();
while( (obj = (Codes) ois.readObject()) != null){
if(obj instanceof Codes){
code_from_file.add(obj);
}
}
}catch (EOFException ex){
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally{
try {
if (ois != null){
ois.close();
}
} catch (IOException ex){
ex.printStackTrace();
}
}
long endR = System.currentTimeMillis();
System.out.println("Read code from file : " + (endR - startR) + "ms");
Is there any faster way for solving this problem?