📄 filereceiver.java
字号:
package chatnew;
import java.net.*;
import java.io.*;
import java.awt.List;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FileReceiver extends Thread {
int port=9998;
String fileName;
List chatContentList;
boolean isOver=false;
// DatagramSocket ds =null;
ServerSocket ss=null;
public FileReceiver(String fileName,List chatContentList) {
this.fileName=fileName;
this.chatContentList=chatContentList;
}
public void run(){
BufferedOutputStream bos=null;
BufferedInputStream bis=null;
try {
// ds = new DatagramSocket(9998);
// bos=new BufferedOutputStream(new FileOutputStream(fileName));
// byte[] buf=new byte[1024];
// DatagramPacket dp=new DatagramPacket(buf,1024);
// while(!isOver){
// ds.receive(dp);
// bos.write(buf,0,dp.getLength());
// bos.flush();
// }
ss=new ServerSocket(port);
Socket s=ss.accept();
bos=new BufferedOutputStream(new FileOutputStream(fileName));
bis=new BufferedInputStream(s.getInputStream());
byte[] buf=new byte[1024];
int i=0;
while((i=bis.read(buf,0,1024))!=-1){
bos.write(buf,0,i);
bos.flush();
}
bis.close();
s.close();
bos.close();
ss.close();
} catch (Exception ex) {
ex.printStackTrace();
// }finally{
// try {
// bos.close();
// } catch (IOException ex1) {
// }
}
}
public void setOver(boolean over){
this.isOver=over;
// ds.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -