📄 clientacceptfile.java~3~
字号:
import java.io.*;
import java.net.*;
import java.util.*;
public class ClientAcceptFile implements Runnable {
Socket acceptFileSocket=null;
DataInputStream dis=null;
DataOutputStream dos=null;
RandomAccessFile raf=null;
File file=null;
String key=null;
static Hashtable saveThread=new Hashtable();
public ClientAcceptFile(String requestPeople,File file,
String ip,int port) {
this.file=file;
key=new String(requestPeople+file.toString());
try{
acceptFileSocket = new Socket(ip, port);
}catch(IOException e){
e.printStackTrace();
}
}
public void run() {
byte[] buffer=new byte[256];
int i=0;
saveThread.put(key,this);
try{
dis=new DataInputStream(acceptFileSocket.getInputStream());
raf=new RandomAccessFile(this.file,"rw");
while((i=dis.read(buffer))!=-1){
raf.write(buffer);
}
}catch(IOException e){
e.printStackTrace();
}finally{
try{
dis.close();
acceptFileSocket.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
public static void main(String[] args) {
// File f=new File()
//Thread thread=new Thread(new ClientAcceptFile("","","",0));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -