Serializing an array in Java

Main.java:

import java.io.*;
 
public class Main
{
   public static void main(String []args) throws Exception {
      String stringArray[] = { "this", "is", "a", "test" };
 
      ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("test.ser"));
      oos.writeObject(stringArray);
      oos.close();
 
      ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.ser"));
      String stringArray2[] = (String[]) ois.readObject();           
      ois.close();
   
      for (int i=0; i<stringArray2.length; i++) {
         System.out.println(stringArray2[i]);
      }
   }
}