Android Question Problem with downloading TXT file with HttpUtils2

Discussion in 'Android Questions' started by Tomas Petrus, Apr 22, 2015.

  1. Tomas Petrus

    Tomas Petrus Active Member Licensed User

    Hi,

    I have problem with TXT file witch I am downloading from server. File has almost 16 kB, so It is small. I am downloading another file with another type in same project with bigger size (150 kB) and It is without problems. TXT file is not complete. It has 8 kB size and it is cut in half in middle of word.

    There is my code:
    Code:
    Dim Job As HttpJob
    Job.Initialize(
    "DownloadMyFile", Me)
    Job.Tag = 
    "file-name.txt"
    Job.Download(
    "http://..../file-name.txt")
    and this is JobDone code:
    Code:
    Case "DownloadMyFile"      
           
    Dim MyPath = File.dirrootexternal & "/download" As String  
           
    Dim out As OutputStream = File.OpenOutput(MyPath , Job.Tag, False)
           
    File.Copy2(Job.GetInputStream, out)
    What I am doing wrong? I am using same code for another files with another file type and it is without problems.

    Thanks for answer
     
  2. Peter Simpson

    Peter Simpson Expert Licensed User

    Hello @Tomas Petrus, try this instead.
    Code:
    Case "DownloadMyFile"
         
    If File.Exists(File.DirDefaultExternal, "file-name.txt"Then File.delete(File.DirDefaultExternal, "file-name.txt")
         
    File.WriteString(File.DirDefaultExternal, "file-name.txt", Job.GetString)
    Also why Job.Tag?
     
    lemonisdead likes this.
  3. Tomas Petrus

    Tomas Petrus Active Member Licensed User

    It works awesome! Thank you much!

    Job.Tag is there because I have function wich is there for more files with diferent name. Name is in Tag
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You are not closing the output stream.
     
    Peter Simpson likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice