public class Util02 {
/**
* 文件下载实现
*/
public File download() throws IOException{
URL url = new URL("http://192.168.1.251/esssweb/Services/GetMasterDbDataHandler.ashx");
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.connect();
InputStream is = http.getInputStream();
OutputStream os = new FileOutputStream(new File("/sdcard/e-SSS/master.zip")) ;
int len = -1;
byte[] bytes = new byte[10240];
while((len = is.read(bytes)) != -1){
os.write(bytes, 0, len);
os.flush();
}
os.close();
is.close();
http.disconnect();
return new File("/sdcard/e-SSS/master.zip");
}---------------------------
public class StartActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
new Util02().download();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}测试android下载,为何下载不到文件,求解
/**
* 文件下载实现
*/
public File download() throws IOException{
URL url = new URL("http://192.168.1.251/esssweb/Services/GetMasterDbDataHandler.ashx");
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.connect();
InputStream is = http.getInputStream();
OutputStream os = new FileOutputStream(new File("/sdcard/e-SSS/master.zip")) ;
int len = -1;
byte[] bytes = new byte[10240];
while((len = is.read(bytes)) != -1){
os.write(bytes, 0, len);
os.flush();
}
os.close();
is.close();
http.disconnect();
return new File("/sdcard/e-SSS/master.zip");
}---------------------------
public class StartActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
new Util02().download();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}测试android下载,为何下载不到文件,求解
解决方案 »
- 急!!求帮看一下android XML的问题T.T
- 寻找一个播放器
- 求android多媒体信息mms模块开发相关的书
- 关于用PC控制android平台?droid VNC server 和screen cast?
- 第一次学ANDROID,做个界面不知道为什么下面那排控件显示不了
- 多线程还是卡住了Activity ------------ 在线讨论,解决立马结贴。
- android在运行时怎么获取当前apk的classes.dex二进制内容
- 使用AsyncHttpClient无法获取网页上的文字
- 为什么SDKManager没有intel atom system image这一项
- 求助
- 关于一个android自定义控件属性的问题?
- 请教如何在Android程序里面嵌入Flash player10.1
参考下里面的downloadFile函数。