public class Foo { public static void main(String[] args) { File f = new File("/tmp/file-2"); ObjectInputStream in; try { in = new ObjectInputStream(new FileInputStream(f)); int numTrees = (int) in.readInt(); double[][] allTheta = (double[][]) in.readObject(); double[][] allX = (double[][]) in.readObject(); int[][] theta_inst_idxs = (int [][]) in.readObject(); double[] y = (double[]) in.readObject(); int[][] dataIdxs = (int [][]) in.readObject(); RegtreeBuildParams params = (RegtreeBuildParams) in.readObject(); in.close(); learnModel(numTrees, allTheta, allX, theta_inst_idxs, y, dataIdxs, params); }catch(Exception e) { e.printStackTrace(); } } /** * Learns a random forest putting the specified data points into each tree. * @see RegtreeFit.fit */ public static RandomForest learnModel(int numTrees, double[][] allTheta, double[][] allX, int[][] theta_inst_idxs, double[] y, int[][] dataIdxs, RegtreeBuildParams params) { boolean writeOutput = true; if(writeOutput) { File f = new File("/tmp/file-2"); f.delete(); try { ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(f)); o.writeInt(numTrees); o.writeObject(allTheta); o.writeObject(allX); o.writeObject(theta_inst_idxs); o.writeObject(y); o.writeObject(dataIdxs); o.writeObject(params); System.out.println("Calls written & deleted to: /tmp/file-2" ); o.close(); } catch(IOException e) { System.err.println(e); } } ... REST OF METHOD ... }