如何从android中的特定url读取一些数据

时间:2010-12-14 09:41:43

标签: android url

如何从android

中的特定网址读取一些数据

2 个答案:

答案 0 :(得分:3)

Try this code in your file:

USE 
url = "your url name+filename.jpg,mp3,etc..."
FileName = "/sdcard/savefilename"


try{
            java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(url).openStream());
            java.io.FileOutputStream fos = new java.io.FileOutputStream(FileName);
            java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
            byte[] data = new byte[1024];
            int x=0;
            while((x=in.read(data,0,1024))>=0){
                bout.write(data,0,x);               
            }
            fos.flush();
            bout.flush();
            fos.close();
            bout.close();
            in.close();
      }
        catch (Exception ex)
        {
         }

答案 1 :(得分:0)

您可以使用HttpClient下载由URL标识的内容。