二维数组序列化问题
import import
import
import
import
public class Test {
public static void main(String[] args){
int c[][] = {{0,0,0,0},{0,1,1,0},{1,0,1,0},{1,1,1,0}};
Num n = new Num(c);
try{
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("qq.txt"));
os.writeObject(n);
}catch(IOException ex){
ex.printStackTrace();
}
}
}
class Num{
int b[][] = new int[4][4];
public Num(int a[][]){
b=a;
}
public int run(){
return b[4][4];
}
public void go(){
try{
ObjectInputStream is = new ObjectInputStream(new FileInputStream("qq.txt"));
Num m =(Num) is.readObject();
for(int j = 0;j< 4;j++){
for(int i =0;i<4;i++){
System.out.print(b[j][i]);
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}
我想把对象所带的二维数组序列化存储,(编译无问题)但是执行该代码后会出现报错
Num
at (Unknown Source)
at (Unknown Source)
at Test.main(Test.java:16)
请问有办法将二维数组序列化么?(我不太想将二维数组拆成一个个数去存储)如果有,请用简单点的方法
谢谢各位了