最简单的方法,
class A
{
string[][] a;
}//write
ByteArrayOutputStream buf = new ByteArrayOutputStream();
ObjectOutputStream o = new ObjectOutputStream(buf);
o.writeObject(s.property);
//read
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()));
A aa = (A)in.readObject();
class A
{
string[][] a;
}//write
ByteArrayOutputStream buf = new ByteArrayOutputStream();
ObjectOutputStream o = new ObjectOutputStream(buf);
o.writeObject(s.property);
//read
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()));
A aa = (A)in.readObject();
o.writeObject(s.property)=>o.writeObject(a)
thank you.
I will try.
呆会给分,嘿嘿
try{ByteArrayOutputStream buf = new ByteArrayOutputStream();
ObjectOutputStream o = new ObjectOutputStream(buf);
o.writeObject(testArray);
FileOutputStream fout=new FileOutputStream("D:\\array.txt");
buf.writeTo(fout);
fout.flush();
fout.close();}
catch(Exception ex){}
执行这段代码后,
很不幸,输出以后是段乱码,怎么办啊?有其他方法吗?
o.writeObject(a);是写对象进去,是不可读的.不是写一个string[][];
你要写写text到file.不用这样做.
String[][] testArray={{"asdasD",aasdad"},{"asdsad",asdsad"},{"dfgfdg","asdasd"}};
ByteArrayOutputStream byteArray=new ByteArrayOutputStream();
for(int i=0;i<3;i++){
for(int j=0;j<2;j++)
try{
byteArray.write(testArray[i][j].getBytes());
}
catch(Exception ex){}
终于写进去了,如何,呵呵。