首页>代码>java swing聊天室程序--带语音>/局域网聊天-带语音/ChatClient/src/FileReceiver.java
import java.net.*;
import java.io.*;
import java.awt.List;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
/*
 * 该类实现文件的接受功能
 * 默认的端口是9998
 */
public class FileReceiver extends Thread 
{
    int port=9900;
    String fileName;
    List chatContentList;
    boolean isOver=false;
    ServerSocket ss=null;
    long count;
    public FileReceiver(String fileName,List chatContentList) 
    {
        this.fileName=fileName;
        this.chatContentList=chatContentList;
    }
    public void run()
    {
        BufferedOutputStream bos=null;
        BufferedInputStream bis=null;
        try 
        {
        	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)
            {
            	count+=1024;
            	ClientFrame.bar.setValue ((int)(count)/1024);
                bos.write(buf,0,i);
                bos.flush();
            }
            bis.close();
            s.close();
            bos.close();
            ss.close();
            JOptionPane.showMessageDialog(null, "接受文件成功!", "提示",JOptionPane.INFORMATION_MESSAGE);
            ClientFrame.bar.setVisible(false);
            ClientFrame.jLabel5.setText("");
            ClientFrame.filelength=0;
        } 
        catch (Exception ex) 
        {
            ex.printStackTrace();
        }
    }
    public void setOver(boolean over)
    {
        this.isOver=over;
    }
}
最近下载更多
微信网友_6444139264921600  LV6 2023年4月29日
Sopuding  LV1 2022年7月16日
tomtom113  LV2 2022年6月9日
ewan007  LV29 2022年4月21日
tdcq123  LV14 2022年3月13日
双方各何必呢  LV13 2021年12月20日
曹思辰  LV6 2021年11月21日
阳光正好  LV2 2021年10月29日
1005948011  LV7 2021年6月1日
服气辣  LV2 2021年5月24日
最近浏览更多
1112WHQ  LV7 2023年11月3日
yuchunxing  LV1 2023年9月2日
2017143155  LV12 2023年6月24日
lynn_zhou  LV1 2023年5月30日
微信网友_6444139264921600  LV6 2023年4月29日
生米的  LV10 2023年3月3日
ann000  LV2 2022年12月7日
queueandstack  LV3 2022年12月1日
微信网友_6229090122354688 2022年11月21日
暂无贡献等级
xinxingyuan8 2022年9月29日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友