Android development, Socket send file, read blocked, not get end of file-1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.