Results 1 to 6 of 6
  1. #1
    LG87 is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default Transfer file get percentage complete

    Going to create a program to transfer files between two different computers via sockets.
    And the only problem I'm currently facing is trying to find a way to get the percentage complete.

    One solution I figured was splitting parts and as I send them, update the percentage.
    (First send information object with full size of file, name and so forth. Then as I send parts of the file it updates how much has been downloaded). Though I hope that there is a simpler method to do this, like getting access to the buffer or something when it is being filled..

    Anyone have a example, or a link to an example which can help me out, I would appreciate it a lot.

  2. #2
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    All you need to do is use the write(byte[],int,int) method of OutputStream to send the file in chunks. Then to get the percentage you divide the number of chunks sent by the total number of chunks and multiply by 100. Good luck!

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    Sorry, what is simpler then sending the size then the data? Given the total size to receive, % is amount received/total size * 100

  4. #4
    LG87 is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Sorry, what is simpler then sending the size then the data? Given the total size to receive, % is amount received/total size * 100
    Sure, but I didn't know you could get the information about how much has been received. Thought when using TCP it will wait and buffer up all of the packets untill its done before it will report/execute next code.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default

    How are you receiving the data? I assumed you were reading it. The read method returns how much was read.
    I don't know how to know how many bytes are on your computer and not ready to be read buried within the TCP etc.

  6. #6
    LG87 is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    How are you receiving the data? I assumed you were reading it. The read method returns how much was read.
    I don't know how to know how many bytes are on your computer and not ready to be read buried within the TCP etc.
    Well, I am reading it from an inputstream attached to the socket. If its just to use another thread or something to check how much has been read, then it shouldnt be a problem (thinking thats how its done).

Similar Threads

  1. writing into file is not complete
    By sara12345 in forum New To Java
    Replies: 4
    Last Post: 04-13-2010, 11:40 PM
  2. file transfer
    By prashant in forum Networking
    Replies: 3
    Last Post: 12-10-2009, 06:46 AM
  3. Regarding File Transfer in TCP/IP
    By manabendra in forum Networking
    Replies: 2
    Last Post: 08-07-2009, 07:51 AM
  4. tcp file transfer
    By ddj in forum Networking
    Replies: 2
    Last Post: 03-20-2009, 02:10 PM
  5. Java File Transfer
    By lks0912 in forum Advanced Java
    Replies: 0
    Last Post: 10-23-2008, 12:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •