📄 senddownloadfile_thread.java
字号:
/*
* SendDownloadFile_thread.java
*
* Created on 2008年4月25日, 下午9:07
*
* 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 SendDownloadFile_thread extends Thread
{
/** Creates a new instance of SendDownloadFile_thread */
String downloadFileName="";
String downloadFilePath="";
public SendDownloadFile_thread(String fp,String fn)
{
downloadFileName=fn;
downloadFilePath=fp;
}
public void run()
{
while(true)
{
try
{
ServerSocket server_socket=new ServerSocket(9000);//9000端口用于传输下载文件
Socket client=server_socket.accept();
File file=new File(downloadFilePath,downloadFileName);
FileInputStream fileIn=new FileInputStream(file);
DataOutputStream out=null;
out=new DataOutputStream(client.getOutputStream());
byte[] buf=new byte[4096];
int num=fileIn.read(buf);
while(num!=-1)
{
out.write(buf);
num=fileIn.read(buf);
}
fileIn.close();
out.close();
}
catch(Exception e)
{
// System.out.println("se");
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -