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下载,为何下载不到文件,求解
解决方案 »
- 我在做安卓工控软件 USB转串口
- m7(CyanogenMod)源码3天没下完,有这么慢吗?
- android -soap 问题~~~~~~~~
- 求助:怎么给Bitmap添加一个遮罩层???
- android的R文件中,没有id是怎么回事啊?
- 更新progressbar出现application not response
- 关于OntouchEvent()函数
- java和c++怎么通信?
- help!初学javaEE+Android,遇到了一些麻烦,恳请指点迷津。
- Openfire服务器怎么打不开
- 关于一个android自定义控件属性的问题?
- 请教如何在Android程序里面嵌入Flash player10.1
参考下里面的downloadFile函数。