URL url = new URL("http://192.168.1.51/res/ban/ad/12/mv/ad1.avi");
HttpURLConnection connect=(HttpURLConnection)url.openConnection();
InputStream input=connect.getInputStream();
File file=new File(Environment.getExternalStorageDirectory()+"/MP4/1.mp4");
OutputStream output=new FileOutputStream(file);
byte buffer [] = new byte[1024];
int i=0;
while((i=input.read(buffer)) !=-1){
output.write(buffer,0,i);
}
output.flush();
设置访问网络的权限:<uses-permission android:name="android.permission.INTERNET"/>
设置SD卡读写权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>