senddownloadfileinfo_thread.java

来自「局域网p2p文件传输」· Java 代码 · 共 86 行

JAVA
86
字号
/*
 * SendDownloadFileInfo_thread.java
 *
 * Created on 2008年4月25日, 下午8:36
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author 602
 */
import java.io.*;
import java.net.*;
import java.util.StringTokenizer;

public class SendDownloadFileInfo_thread extends Thread
{
    /** Creates a new instance of SendDownloadFileInfo_thread */
    DataOutputStream out=null;
    DataInputStream in=null;
    Socket server=null;
    String desIP="";;
    String fileInfo="";
    
    String downloadFileName="";
    String downloadFilePath="";
    
    public SendDownloadFileInfo_thread() 
    {
    }
    
    public void run()
    {
        try
        {
            desIP=MainJFrame.jTextField1.getText();
            server = new Socket(desIP,7000);//7000端口传输选中下载文件的信息
        }
        catch(IOException e1)
        {
            System.out.println("正在连接");
        }
        
        try
        {
            in=new DataInputStream(server.getInputStream());
            out=new DataOutputStream(server.getOutputStream());
        }
        catch(IOException e2)
        {}
        
        try
        {
            fileInfo = MainJFrame.list2.getSelectedItem();
            int index=fileInfo.lastIndexOf("->");
            fileInfo=fileInfo.substring(0,index);//得到文件的路径和名字  F:\\3.jpg
            out.writeUTF(fileInfo);
            
            index=fileInfo.lastIndexOf("\\");
            downloadFileName=fileInfo.substring(index+1,fileInfo.length());
            downloadFilePath=fileInfo.substring(0,index+1);
            
            server.close();
            out.close();
            in.close();
        }
        catch(IOException e)
        {}
        
        ReceiveDownloadFile_thread receiveDownloadThread=new ReceiveDownloadFile_thread(MainJFrame.jTextField2.getText().toString(),downloadFileName);
        receiveDownloadThread.start();
    }
    
}









⌨️ 快捷键说明

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