当前位置: 首页 > 工具软件 > RMIIO > 使用案例 >

Java API——RMIIO入门教程(4)远程流传输示例之RMIIO客户端码

长孙阳成
2023-12-01

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();
		}
	}
}


 类似资料: