希望我能够正确解释这个……
我能够连接到我的Web服务器并下载单个文件.我现在尝试做的是连接到我的服务器并从特定文件夹下载所有苍蝇.在这种情况下,我想下载图像.
这是我用来下载单个文件的代码……
我能够连接到我的Web服务器并下载单个文件.我现在尝试做的是连接到我的服务器并从特定文件夹下载所有苍蝇.在这种情况下,我想下载图像.
这是我用来下载单个文件的代码……
URL url = new URL("http://127.0.0.1/Folder/file.csv"); URLConnection conexion = url.openConnection(); conexion.connect(); int lenghtOfFile = conexion.getContentLength(); InputStream is = url.openStream(); File testDirectory = new File(Environment.getExternalStorageDirectory()+"/Folder"); if(!testDirectory.exists()){ testDirectory.mkdir(); } FileOutputStream fos = new FileOutputStream(testDirectory+"/file.csv"); byte data[] = new byte[1024]; int count = 0; long total = 0; int progress = 0; while ((count=is.read(data)) != -1){ total += count; int progress_temp = (int)total*100/lenghtOfFile; if(progress_temp%10 == 0 && progress != progress_temp){ progress = progress_temp; } fos.write(data,count); } is.close(); fos.close();
解决方法
原文地址:https://www.jb51.cc/android/318390.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。