File download problem?

Put your problem here if it does not fit any of the other categories.

File download problem?

Postby iceking » Mon Feb 11, 2008 11:00 am

I try to download a file from server to android(client).I have a problem. The program will stop in front of the folloeing raw.I use log cat to debug my code I found following code were not be run.

Code: Select all
DataInputStream datainstream = new DataInputStream(datasocket.getInputStream());
         FileOutputStream fos = new FileOutputStream(downloadFile);

         while(messagein != -1){
              messagein = datainstream.readInt();     
              fos.write(messagein);
          }
          messageTextArea.setText("File is downloaded successfully!\n");
         datasocket.close();


I look some Tutorials try to slove this problem. I change my code like following. However it's still not work.

Code: Select all
DataInputStream datainstream = new DataInputStream(datasocket.getInputStream());
           FileOutputStream fos = openFileOutput(downloadFile, MODE_WORLD_READABLE);
           OutputStreamWriter osw = new OutputStreamWriter(fos);
               while(messagein != -1){
                     messagein = datainstream.readInt();     
                     osw.write(messagein);
                }
           messageTextArea.setText("File is downloaded successfully!\n");
           datasocket.close();
iceking
Freshman
Freshman
 
Posts: 8
Joined: Wed Jan 23, 2008 6:47 pm
Location: Taiwan

Top

Postby plusminus » Mon Feb 11, 2008 3:50 pm

Hello iceking,

did you have a look at this tutorial: :src: Getting Data From the Web (URLConnection via http).
It works really fine (except all the Proxy issues).

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 20 guests