80,352
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
InputStream is = null;
HttpURLConnection conn=null;
try {
URL url = new URL("http://www.dubblogs.cc:8751/Android/Test/Apk/EX04_14.apk");
conn = (HttpURLConnection) url.openConnection();
conn.connect();
is = conn.getInputStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
FileOutputStream fos = null;
BufferedInputStream bis = null;
try {
fos = new FileOutputStream("e:/test4.apk");
byte[] buf = new byte[1024];
bis = new BufferedInputStream(is);
while (bis.read(buf,0,1024) != -1) {
fos.write(buf);
System.out.println(buf);
}
fos.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if (fos != null)
fos.close();
if (bis != null)
bis.close();
if (is != null)
is.close();
conn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
int size = -1;
while ((size = bis.read(buf)) != -1) {
fos.write(buf, 0, size);
Log.e(TAG, buf + ":buf");
}