求救,通过RMI如何把远程的文件copy到本地,应该靠传递什么呢???

hjw0571 2006-01-13 09:43:19
我用 FileInputStream传递,
老报错:
ava.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.io.FileInputStream
...全文
137 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhmt 2006-04-28
  • 打赏
  • 举报
回复
上面是发送
基本就这样子啊
zhmt 2006-04-28
  • 打赏
  • 举报
回复
sock = new Socket(addr, port);
fs = new BufferedOutputStream(new FileOutputStream(savePath));
out = new BufferedOutputStream(sock.getOutputStream());
in = new BufferedInputStream(sock.getInputStream());


System.out.println("start to recv....");
byte[] b = new byte[5120];
long recvSize = 0;
for (int tmp = -1; (tmp = in.read(b)) != -1;) {
fs.write(b, 0, tmp);
}

fs.close();
out.close();
in.close();
sock.close();
zhmt 2006-04-28
  • 打赏
  • 举报
回复
不用这样传递文件吧?
用sock自己写吧:
发送:
out = new BufferedOutputStream(sock.getOutputStream());
in = new BufferedInputStream(sock.getInputStream());


fis = new FileInputStream(file);

byte[] b = new byte[5120];
for(int tmp=0;(tmp=fis.read(b))!=-1; )
{
out.write(b,0,tmp);
}
if(fis!=null)fis.close();
if(out!=null)out.close();
if(sock!=null)sock.close();
hjw0571 2006-01-13
  • 打赏
  • 举报
回复
public class HelloServer extends UnicastRemoteObject implements Hello,Serializable
public class HelloClient implements Serializable

我服务器,客户端 现在都加了,还是不行
hjw0571 2006-01-13
  • 打赏
  • 举报
回复
请问那个类,实现这个接口
是服务器,远程接口,还是客户端
xiaobzg 2006-01-13
  • 打赏
  • 举报
回复
implement Serializable

62,629

社区成员

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

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