快速业务通道

CS结构软件自动升级实现(三) - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-16
闭资源及链接 156 socketOut.close(); 157 socketIn.close(); 158 socket.close(); 159 Config.print("自动升级处理完毕"); 160 }catch(Exception e) 161 { 162 Config.print("升级处理失败,"+e); 163 e.printStackTrace(); 164 } 165 } 166 private void openFile(String file) 167 { 168 try 169 { 170 Runtime.getRuntime().exec("cmd /c "+file); 171 }catch(Exception e) 172 { 173 e.printStackTrace(); 174 } 175 } 176 private String receiveFileAbsPath(byte flag) 177 { 178 String absPath = ""; 179 //接收文件全路径 180 try 181 { 182 //接收数据缓冲区 183 byte flagb[] = new byte[1];//标志 184 byte lenb [] = new byte[4];//长度 185 //接收文件全路径 186 StringBuffer strBuf = new StringBuffer();//用于接收信息 187 int len = -1; 188 boolean isFirst = true; 189 boolean isOk = false; 190 flagb[0] = flag; 191 while(true) 192 { 193 //第一次 194 if(isFirst) 195 { 196 isFirst = false; 197 }else 198 { 199 len = socketIn.read(flagb,0,1);//读取标识位 200 if(len != 1) 201 { 202 Config.print(socket.getInetAddress() + ":读取数据标识位失败"); 203 break; 204 } 205 } 206 //读取数据长度 207 if(flagb[0]==AUPD.MARK_DATA_SECT) 208 { 209 len = socketIn.read(lenb, 0, 4); 210 if (len != 4) 211 { 212 Config.print(socket.getInetAddress() + ":读取数据头部失败"); 213 break; 214 } 215 } 216 if (flagb[0] == AUPD.MARK_DATA_SECT)//数据内容 217 { 218 int cLen = Integer.parseInt(new String(lenb, 0, 4));//数据内容长度 219 byte data[] = new byte[cLen]; 220 len = socketIn.read(data, 0, cLen); 221 System.out.println("len:"+len+"cLen="+cLen+">>"+new String(data,0,len)); 222 int totLen = len; 223 while (totLen < cLen)//不足位要重重读取 224 { 225 strBuf.append(new String(data, 0, len)); 226 len = socketIn.read(data, 0, cLen - totLen); 227 totLen = totLen + len; 228 System.out.println("len:"+len+"cLen="+cLen); 229 } 230 strBuf.append(new String(data, 0, len)); 231 }else if(flagb[0]==AUPD.MAR

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号