送分了:)如何将一些需要输出的东西写到ByteArrayOutputStream输出流中,如一个二维数组String[][]。

leolee 2001-08-30 02:55:03
如一个二维数组String[][],写到ByteArrayOutputStream中,如何操作??
...全文
264 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
leolee 2001-08-31
  • 打赏
  • 举报
回复
呵呵,谢了。不过我有方便的方法了。
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){}
终于写进去了,如何,呵呵。

cming 2001-08-31
  • 打赏
  • 举报
回复
用o.writeChars(String);来写.分成n个一唯依此写进去.
zytang 2001-08-31
  • 打赏
  • 举报
回复
gz
leolee 2001-08-31
  • 打赏
  • 举报
回复
这个原因啊,但是我必须返回ByteArrayOutputStream类型的
cming 2001-08-30
  • 打赏
  • 举报
回复
你这样写不对.
o.writeObject(a);是写对象进去,是不可读的.不是写一个string[][];
你要写写text到file.不用这样做.

leolee 2001-08-30
  • 打赏
  • 举报
回复
String[][] testArray={{"asdasD",aasdad"},{"asdsad",asdsad"},{"dfgfdg","asdasd"}};
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){}
执行这段代码后,
很不幸,输出以后是段乱码,怎么办啊?有其他方法吗?
leolee 2001-08-30
  • 打赏
  • 举报
回复
to cming:
thank you.
I will try.
呆会给分,嘿嘿
cming 2001-08-30
  • 打赏
  • 举报
回复
一不小心把我的代码写出来了.
o.writeObject(s.property)=>o.writeObject(a)
cming 2001-08-30
  • 打赏
  • 举报
回复
最简单的方法,
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();
leolee 2001-08-30
  • 打赏
  • 举报
回复
啊?
变成一位数组后如何写进去呢?
哎,可以写两句代码吗?我笨,55
skyyoung 2001-08-30
  • 打赏
  • 举报
回复
变成一维写进去,出来时再构造成二维。
leolee 2001-08-30
  • 打赏
  • 举报
回复
大家照顾一下吗,我急阿
leolee 2001-08-30
  • 打赏
  • 举报
回复
没人能告诉我吗??????????

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧