⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileclient.java

📁 JAVA开发的采用RMI远程机制
💻 JAVA
字号:
package ftp;

import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import java.rmi.*;


public class fileClient
{
  public static void main(String[] args)
  {
      new client();
   
  }	

}

class client extends JFrame implements ActionListener
{
	
  JList jl = new JList();	
  JButton jbview = new JButton("查看");
  JButton jbdown = new JButton("下载");
  JButton jup = new JButton("上传");
  //JTextField jf = new JTextField(15);
  public client()
  {
  	 this.getContentPane().setLayout(new FlowLayout());
     this.getContentPane().add(jbdown);
     this.getContentPane().add(jbview);
    // this.getContentPane().add(jf);
     this.getContentPane().add(jup);
     this.getContentPane().add(jl);
     
     this.jbdown.addActionListener(this);
     this.jbview.addActionListener(this);
     this.jup.addActionListener(this); 
      
      this.setTitle("client");
      this.setSize(400,400);
      this.show();
     
 }
  
 public void actionPerformed(ActionEvent e)
 {
 	if(e.getSource()==this.jbview)
 	{
 	   try{
 	   	    fileinterface fi = (fileinterface)Naming.lookup("rmi://localhost/RemoteService");
 	   	    String[] names = fi.getCurrFileNames();
 	   	    
 	   	    jl.setListData(names);
 	   	
 	   	   
 	   	  }	
 	 
 	    catch(Exception eee)
 	      {
 	      	 System.out.println(eee);
 	      }
 	}
 
    if(e.getSource()==this.jbdown)
    {
       	
       try{   //reserch RMI object
 	   	    fileinterface fi = (fileinterface)Naming.lookup("rmi://localhost/RemoteService");
 	        String ss = (String)this.jl.getSelectedValue();
 	        //ss is choose to the want to be downloaded file
 	        File ff = fi.downLoad(ss);
 	        
 	        File fff = new File("e:\\download\\"+ss);   //creat downloade file
 	        fff.createNewFile();
 	        FileInputStream fin = new FileInputStream(ff);
 	        FileOutputStream fout = new FileOutputStream(fff);
 	        byte[] bb = new byte[1000000];
 	       fin.read(bb);  
 	       fout.write(bb,0,bb.length);
 	         
 	    }
    
       catch(Exception ee)
       {
         System.out.println(ee);	
       }
     } 
     if(e.getSource()==this.jup)
     {
        JFileChooser jfc = new JFileChooser();
        if(jfc.showOpenDialog(this)==JFileChooser.OPEN_DIALOG); 	
        {
          
         try{
         	 byte[] bb = new byte[10000000];
             File ff = jfc.getSelectedFile();
             FileInputStream fin = new FileInputStream(ff);
             fin.read(bb); 	     //read the want to uploaded file to arry bb
             String s = ff.getName();	 //get filename;
             fileinterface fi = (fileinterface)Naming.lookup("rmi://localhost/RemoteService");
             //reserch RMI object
             fi.upLoad(s,bb);             //uploade file
     
            }
          catch(Exception e2)
          {
          	
            System.out.println(e2);
          }  
     
        }
      }
     
  
   }  
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -