/**
* 将一个InputStream里面的数据写入到SD卡中
* @param path
* @param fileName
* @param input
* @return
*/
public File write2SDFromInput(String path,String fileName,InputStream input){
File file = null;
OutputStream output = null;
try {
createSDDir(path);
String str = path + fileName;
file = createSDFile(path + fileName);
output = new FileOutputStream(file);
byte[] buffer = new byte[FILESIZE];
while((input.read(buffer)) != -1){
output.write(buffer);
}
output.flush();
}
catch (Exception e) {
e.printStackTrace();
}
finally{
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
如何在下载代码中加阻塞,让他下载完再执行后面的程序。请各位帮忙看看
代码如下:下载和显示都在一个单击时间里面//ListView单击事件
list_view_presentation.setOnItemClickListener(new OnItemClickListener(){
.
.
.
.
.
.
//下载函数downFile
int result = downloader.downFile("http://172.16.0.78:8082/upload/download/"+presentationName+"/"+presentationName+"_1.jpg", "download/"+presentationName+"/", presentationName+"_1.jpg");
//接下来就是现实图片的方法了
sum =1;
setHtml(imagePath+presentationName+"/"+presentationName+"_1.jpg");
imageName = presentationName;
webview.loadDataWithBaseURL("about:blank", html, "text/html", "utf-8",null);
webview.setVisibility(View.VISIBLE);
}}); }
Android显示在线图片
while(true){
if("判断如果下载完"){
break;
}
}
下载完要运行的语句....