1
我有文件下载问题,无法下载Android手机中的文件 - Android ..?
我能够在模拟器中下载文件,但它不适用于手机。 我已经定义了互联网的权限,并写入SD卡。
我在服务器上有一个doc文件,如果用户点击下载。它下载文件。此在模拟器中正常工作,但不能在电话工作,
Plz帮助我找到解决方案。
谢谢。
* 编辑* 我下载的文件
public void downloadFile(String _url, String fileName) {
File PATH = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
try {
PATH.mkdirs();
URL url = new URL(_url); // you can write here any link
File file = new File(PATH, fileName);
long startTime = System.currentTimeMillis();
Log.d("Manager", "download begining");
Log.d("DownloadManager", "download url:" + url);
Log.d("DownloadManager", "downloaded file name:" + fileName);
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
Log.d("ImageManager",
"download ready in"
+ ((System.currentTimeMillis() - startTime)/1000)
+ " sec");
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}
logcat中的任何错误?也许一些代码片段? – 2012-02-09 09:22:53
粘贴一些代码,用这个信息很难帮你:) – oriolpons 2012-02-09 09:23:58
Nop,logcat不会给出任何错误。 – 2012-02-09 09:24:20