希望我能够正确解释这个...我能够连接到我的网络服务器并下载单个文件.我现在尝试做的是连接到我的服务器并从特定文件夹下载所有苍蝇.在此我想下载图像的情况.这是我用来下载单个文件的代码......
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, 0, count);
}
is.close();
fos.close();
Run Code Online (Sandbox Code Playgroud)
如何添加此代码以使其从该文件夹下载所有文件?
| 归档时间: |
|
| 查看次数: |
11122 次 |
| 最近记录: |