学习感言(3)
日期:2011-08-23
点击:25
来源: 未知
分享至:
9999);
20
21 System.out.println(\"服务器连接成功.....\");
22 dos = new DataOutputStream(s.getOutputStream());
23 fis = new FileInputStream(new File(filename));
24 } catch (UnknownHostException e) {
25 e.printStackTrace();
26 } catch (FileNotFoundException e) {
27 e.printStackTrace();
28 } catch (IOException e) {
29 e.printStackTrace();
30 }
31 }
32
33 //发送文件
34 public void SendFile(){
35 System.out.println(\"开始传输文件....\");
36 int result=0;
37 try {
38 while((result = fis.read(sendbyte,0,sendbyte.length))>0){
39 dos.write(sendbyte);
40 dos.flush();
41 }
42 } catch (IOException e) {
43 e.printStackTrace();
44 }
45 closeAll();
46 }
47
48 //关闭所有流
49 public void closeAll(){
50 try {
51 fis.close();
52 } catch (IOException e2) {
53 e2.printStackTrace();
54 }
55 try {
56 dos.close();
57 } catch (IOException e1) {
58 e1.printStackTrace();
59 }
60 try {
61 s.close();
62 } catch (IOException e) {
63 e.printStackTrace();
64 }
65
66 }
67
68
69
70 public static void main(String[] args) {
71 ClientTCPSend c = new ClientTCPSend(\"C:/Documents and Settings/Administrator/桌面/send.jpg\");
72 c.SendFile();
73
74
75 }
76
77 }
宁愿跑起来被拌倒无数次,也不愿规规矩矩走一辈子。就算跌倒也要豪迈的笑!