📄 clientth.java~1~
字号:
package filetran;import java.net.*;import java.io.*;import javax.swing.*;import java.util.*;/** * <p>Title: FileTran</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author Netf * @version 1.0 */public class clientth extends Thread{ Socket client=null; OutputStream out=null; FileInputStream fis=null; String filestr=null; FileTranFram frame; JTextField jtf; JLabel status; JProgressBar jpb; float fileda; int data; float sps; float speed; byte buf[]=new byte[1024]; public clientth(Socket s,String filestr,FileTranFram f) { this.frame=f; status=frame.statusBar; fileda=0; this.client=s; jtf=frame.files; jpb=frame.jpb; this.filestr=jtf.getText().trim(); } public void run(){ try{ status.setText("已连接..."); out=client.getOutputStream(); }catch(IOException e){} try{ // JOptionPane.showMessageDialog(frame,jtf.getText().trim()); fis=new FileInputStream(filestr); float filesize=fis.available()/1024; //JOptionPane.showMessageDialog(frame,filesize+""); status.setText("开始发送..."); jpb.setVisible(true); while((data=fis.read(buf))!=-1){ ////////starttime///////////// Calendar start=new GregorianCalendar(); float shour=start.get(Calendar.HOUR_OF_DAY); float smin=start.get(Calendar.MINUTE); float ssec=start.get(Calendar.SECOND); float sn=start.get(Calendar.MILLISECOND); //////////////////// out.write(buf,0,data); ////////////endtime/////////////// Calendar end=new GregorianCalendar(); float ehour=end.get(Calendar.HOUR_OF_DAY); float emin=end.get(Calendar.MINUTE); float esec=end.get(Calendar.SECOND); float en=end.get(Calendar.MILLISECOND); float spss=(ehour-shour)*3600+(emin-smin)*60+(esec-ssec)+(en-sn)/1000; sps+=spss; fileda+=1; // if(sps>0){ speed=fileda/sps; // } float fv=(fileda/filesize)*100; int fx=Math.round(fv); jpb.setValue(fx); //jpb.setString(fx+"%"); status.setText("正在发送文件...已发送:"+fileda+"kb, "+fx+"%, 速度" +Math.round(speed)+"KB/秒"); } out.close(); fis.close(); client.close(); // JOptionPane.showMessageDialog(frame,sn+"/"+en+""); status.setText("文件发送完毕...共:"+fileda+"kb,用时:"+Math.round(sps) +"秒, 速度:"+Math.round(speed)+"字节/秒"); }catch(IOException e){ JOptionPane.showMessageDialog(frame,"clientth err"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -