- byte[]
- buffer=new byte[1024];
- private DataInputStream myDataInputStream = new DataInputStream(new BufferedInputStream(mySocket.getInputStream()));
- private FileOutputStream myFileOutputStream = new FileOutputStream(new File("C\\:test.png"));
- public void getFile(){
- int count=0;int all=0;
- /*do{count=myDataInputStream.read(buffer,0,buffer.length);
- myFileOutputStream.write(buffer,0,count);
- all+=count;//记录一共接收了多少文件
- }
- while(count>-1);
- */
- while((count=myDataInputStream.read(buffer,0,buffer.length))!=-1){
- myFileOutputStream.write(buffer,0,count);
- all+=count;//记录一共接收了多少文件
- }
- }
复制代码
你用do while循环中 do肯定会执行一次。 |