This is my receive file code: Start can read to 1, but now it is not read, so add the red Word resolved (the code of the comment)
File File =NewFile (Mfilepath, "Chetou.") +Entity.mediatype); if(!file.exists ()) file.createnewfile (); FileOutputStream Fos=NewFileOutputStream (file);//Save the received file to the corresponding path byte[] Sendbytes =New byte[1024]; intTranslen =0; LOG.V (TAG,"----Start receiving files <" + Entity.params + ", File size is <" + Filelength + ">----"); while(true){ intRead =0; Read=Dis.read (sendbytes); LOG.V (TAG,"Read=" +read); if(Read = =-1) Break; Translen+=Read; LOG.V (TAG,"Receive file Progress" +100 * translen/filelength + "% ..."); Fos.write (Sendbytes,0, read); Fos.flush (); /*if (translen==filelength) break;*/ } LOG.V (TAG,"----Receive file <" + Entity.params + "> success-------1"); Entity.filepath= mfilepath+ "/chetou." +entity.mediatype;//assign the downloaded file name to Entity.filepathLOG.V (TAG, "----Receive file <" + Entity.params + "> Success-------2");
Code to send the file:
// Transferring Files FileInputStream FIS =new fileinputstream (file); byte [] sendbytes =newbyte[1024x768]; int length =0; while (length = Fis.read (sendbytes,0, sendbytes.length)) >0) { dos.write (sendbytes,0, length); Dos.flush (); } Fis.close (); " After sending the file data ");
Android development, Socket send file, read blocked, not get end of file-1