我一直在尝试实现一种将一些对象保存在文件中的方法,这样我就可以减少每次运行时填充变量的需要,这可能需要 20 分钟以上的时间。我目前正在使用一个名为 Raster 的对象,可以使用用于将数据拉入字段的文件类型来填充该对象。我想知道如何能够序列化以下内容。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
public class Raster implements Serializable {
private static final long serialVersionUID = 15L;
private int col,row,NODATA;
private double [] [] Ras;
public Raster (File inData) throws IOException
{
//open file as f
BufferedReader f = new BufferedReader(new FileReader(inData));
this.col = Integer.parseInt(f.readLine().substring(5).trim());
this.row = Integer.parseInt(f.readLine().substring(5).trim());
f.readLine();
f.readLine();
f.readLine();
this.NODATA = Integer.parseInt(f.readLine().substring(12).trim());
//now the data will be added
this.Ras = new double [row] [col];
for (int r …Run Code Online (Sandbox Code Playgroud)