将一个二维数组装入输入流,并利用输入流读取该数组并打印。
来源:百度知道 编辑:UC知道 时间:2024/07/07 16:36:30
请把代码 写出来!
//:DataTrans.jaav
//修正了对 JDK1.4 的支持
import java.io.*;
//通过管道来处理此类问题
public class DataTrans {
public static void main(String[] args) throws Exception{
//基本数据传送
int[][] dat = {{1,2,3},{4,5,6,},};
//新建输出管道对象
PipedOutputStream out = new PipedOutputStream();
//新建输入管道对象
PipedInputStream in = new PipedInputStream();
//两个对象进行连接
out.connect(in);
//以对象的方式向管道写入数据
ObjectOutputStream oos = new ObjectOutputStream(out);
//以对象的方式从管道读取数据
ObjectInputStream oin = new ObjectInputStream(in);
oos.writeObject(dat);//写对象
oos.flush();
oos.close();
Object readobj = oin.readObject();//读取对象
oin.close();
//打印读取到的对象
int[][] dat2 = (int[][])readobj;
for(int i=0; i<dat2.length; i++){
for(int j=0; j<dat2[i].length; j++)
System.out.print(dat2[i][j]);
System.out.println();
}
//对象传送
Objec