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

📄 receivedownloadfile_thread.java

📁 局域网p2p文件传输
💻 JAVA
字号:
/*
 * ReceiveDownloadFile_thread.java
 *
 * Created on 2008年4月25日, 下午9:27
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

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

public class ReceiveDownloadFile_thread extends Thread
{
    /** Creates a new instance of ReceiveDownloadFile_thread */
    String downloadFileName="";
    String downloadFilePath="";
    String desIP="";
    public ReceiveDownloadFile_thread(String fp,String fn) 
    {
        downloadFileName=fn;
        downloadFilePath=fp;
    }
    
    public void run()
    {
        try
        {
            desIP=MainJFrame.jTextField1.getText();
            Socket server=new Socket(desIP,9000);//9000端口用于传输下载文件
            File file=new File(downloadFilePath,downloadFileName);
            if(file.exists())
            {
                file.delete();
            }
            file.createNewFile();
            RandomAccessFile wFile=new RandomAccessFile(file,"rw");
            
            
            DataInputStream in=null;
            in=new DataInputStream(server.getInputStream());

            byte[] buf=new byte[4096];
            int num=in.read(buf);

            while(num!=(-1))
            {
                    wFile.write(buf);
                    num=in.read(buf);
            }
            MainJFrame.jLabel2.setText("下载完毕");
            in.close();
            wFile.close();
        }
        catch(Exception e)
        {System.out.println("re");}
    }
}






⌨️ 快捷键说明

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