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

📄 filereceiver.java

📁 使用java语言写的聊天工具
💻 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;
    }
}

⌨️ 快捷键说明

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