how to iterate through files

I have got a few 2d arrays serialized in a folder. I would like to know how to deserialize all of them without having to assign each of them to an array separately. So how to iterate through files in a folder to assign them to arrays automatically.
Who is Participating?
Sure  you can list all files in the folder like:

File fdir = new File("folder_name");

String [] fileNames = fider.list();

You may want to store your arrays in say ArrayList

ArrayList al = new ArrayList();

for (int j=0; j<fileNames.length; j++){
  FileInputStream fis = new FileInputStream("C:\\Users\\chudy\\Desktop\\Work\\database\\" + filenames[j]);
  double [] [] array =...


Sorry, I'm not sure I understand. Are you asking how to iterate through files in the folder? Can you elaborate a little bit?
chudyksgAuthor Commented:
e.g. I have 5 files in a folder all of them are serialized 2d arrays.

now what I am doing is I am serializing them manually like this:

double[][] rockstar = deserializeFingeprintList("rockstar.ser");
double[][] hardtimes = deserializeFingeprintList("hardtimes.ser");

 public static double[][] deserializeFingeprintList(String name) throws FileNotFoundException, IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("C:\\Users\\chudy\\Desktop\\Work\\database\\" + name);
        ObjectInputStream ois = new ObjectInputStream(fis);
        double[][] array = (double[][]) ois.readObject();

        return array;

Open in new window

what I want is a loop that iterates through a folder and de serializes these files automatically
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.