Android Question Downloading a text file from a server

Carthalion

Member
Licensed User
Longtime User
Please do not chastise me for not trying to research this first. I have spent most of the day reading examples for HTTP, HttpUtils2, OKHTTP & OKHttpUtils2. One shows how to populate a string array. Another, a huge image file but I cannot get it to work.

I think that what I am trying to do is fairly simple. I want to download and save a text file from a server. This code seems to work:

Dim job As HttpJob
job.Initialize("Job", Me)
job.Download("http://www.MyServer.com/textfiles/MyFile.txt")

The Sub JobDone gives me a success message. But where is the file? I don't know.

Can I get a code sample that finds the server and saves the file to my project?

Thanks,

Carthalion
 

Carthalion

Member
Licensed User
Longtime User

Hi lemonisdead and thank you for your input. These are both samples that I have tried to make work. I get an error. (Screen shot attached.) If you can look at my code and tell me what you see, I would appreciate it.

Also, I can't call the JobDone Sub. It wants a missing parameter and I cannot determine what it would be.

Dim job As HttpJob
job.Initialize("j", Me)
job.Download("http://www.MyServer.com/textfiles/MyFile.txt")

Sub JobDone(job As HttpJob)
If job.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "filename.dat", False)
File.Copy2(job.GetInputStream, out)
out.Close '<------ very important
Else
Log("Error: " & job.ErrorMessage)
End If
job.Release
End Sub

Thank you,

Carthalion
 

Attachments

  • JobDone error002.jpg
    JobDone error002.jpg
    68.8 KB · Views: 359
Upvote 0

Carthalion

Member
Licensed User
Longtime User
The attached sample project works fine for me?

Actually, the code works for me also when I put it (and it only) in a new project. So there must be something else causing the error. I do still have a question that I hope you can help me with. When I run the code, I get the success message that the file was downloaded. But where is it? I would think that it would show up in my files folder but it is not there. When you ran the code, did you get a text file (InetLoLo.text)?

Thank you for your help!
 
Upvote 0
Top