RMI Client Class,注意InputStream转换为RemoteInputStream
package com.sinosuperman.rmiio2;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import com.healthmarketscience.rmiio.RemoteInputStreamServer;
import com.healthmarketscience.rmiio.SimpleRemoteInputStream;
public class RmiioClient2 {
public static void main(String[] args) {
try {
RmiioService2 service = (RmiioService2) Naming.lookup("rmi://localhost:2234/testrmiio");
String rootPath = System.getProperty("config");
String filePath = rootPath + File.separator + "temp/test.txt";
InputStream inStream = new FileInputStream(filePath);
RemoteInputStreamServer remoteFileData = new SimpleRemoteInputStream(inStream);
service.sendFile("result.txt", remoteFileData.export());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}