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

📄 doit.java

📁 java网络文件传输源代码
💻 JAVA
字号:
package filetran;import java.io.*;import java.util.*;import java.net.*;import javax.swing.*;import javax.swing.table.*;/** * <p>Title: FileTran</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author Netf * @version 1.0 */public class doit extends Thread{  static String str=null;  String msg[]=new String[3];  String filepath;  JTextField jtf;  JLabel status;  String sadd;  String localadd;  DatagramPacket dp;  private static String cfile;  FileTranFram frame;  String Path;  DefaultTableModel dtm;  static long flen;  private int rowcount=0;  public doit(DatagramPacket dp, FileTranFram ftf) {    this.dp=dp;    str=new String(dp.getData());    str=str.trim();    sadd=dp.getAddress().getHostAddress();    this.frame =ftf;    dtm=ftf.dtm;    rowcount=dtm.getRowCount();    //JOptionPane.showMessageDialog(frame,str);    StringTokenizer st=new StringTokenizer(str,"|");    int i=0;    while(st.hasMoreTokens()){      msg[i++]=st.nextToken();    }    if(msg[0].equals("get?")){       flen=Long.parseLong(msg[1]);   }    jtf=frame.files;    filepath=jtf.getText();    status=frame.statusBar;    //sadd=frame.Ipstr.getText();    try{    localadd=InetAddress.getLocalHost().getHostAddress();    }catch(IOException e){}  } public void run(){   if(msg[0].equals("get?")){       status.setText("有人请求...");       String msgs=sadd+"想发送文件【"+msg[2]+"】大小:"+flen/1024+"MB给你,是否接收?";      int result=JOptionPane.showConfirmDialog(frame,msgs);      if(result==JOptionPane.YES_OPTION){           status.setText("你同意接收...");           JFileChooser jfc=new JFileChooser();          // jfc.setDialogType(JFileChooser.SAVE_DIALOG);          jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);          jfc.showDialog(frame,"请选目录");         //jfc.setSelectedFile(new File("xx.java"));         if(jfc.getSelectedFile()!=null){             Path=jfc.getSelectedFile().getPath();            if(!Path.endsWith("\\")){                cfile=Path+"\\"+msg[2];             }else{                cfile=Path+msg[2];}        // JOptionPane.showMessageDialog(frame,"get"+msg[2]);         sendmsg smsg=new sendmsg(sadd,"ok|"+localadd+"|get");         smsg.send();}      }else{         status.setText("你拒绝接收...");         sendmsg smsg=new sendmsg(sadd,"no|"+localadd+"|no");         smsg.send();      }   }   if(msg[0].equals("ok")){     status.setText("对方确认接收...");    // JOptionPane.showMessageDialog(frame,"ok"+msg[2]);     sendmsg smsg=new sendmsg(sadd,"come|"+"1235|"+localadd);     smsg.send();     sendfile sf=new sendfile(filepath,frame,rowcount);     sf.start();   }   if(msg[0].equals("come")){     status.setText("准备与发送方连接...");    // JOptionPane.showMessageDialog(frame,"come"+msg[2]);     getfile gf=new getfile(sadd,Integer.parseInt(msg[1]),cfile,frame,rowcount,flen);     status.setText(String.valueOf(gf.getspeed()));     gf.get();   }   if(msg[0].equals("no")){       status.setText("!!!对方拒绝接收...");   } }}

⌨️ 快捷键说明

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