这是我在尝试下载文件时遇到的一个奇怪错误,我需要打开输入流,然后将读取的数据写入输出流。。。输入流不工作。。。调试时没有错误。。但它似乎只是挂在那里,键盘上的F6似乎不起作用。。。。必须终止调试会话。。。我做错了什么???
try{
URL url = new URL(pdfurl);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d("k", "Lenght of file: " + lenghtOfFile);
//InputStream s=file
InputStream s=url.openStream();
InputStream input = new BufferedInputStream(s);
OutputStream output = new FileOutputStream(file);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress((int)((total*100)/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}
catch (Exception e)
{
download_flag = true;
String s=e.getMessage().toString();
Log.d("k","exception occured"+s);
}
您可以尝试HttpGet请求:
HttpGet httpGet = new HttpGet(url);
HttpClient httpclient = new DefaultHttpClient();
// Execute HTTP Get Request
HttpResponse response = httpclient.execute(httpGet);
content = response.getEntity().getContent();