我需要从我的SD卡上的目录中获取所有文件,然后将ArrayList发送到PHP服务器,但我保存了很好的ArrayList,但它总是发送Empty,但它的编译不会报告任何错误。
我的代码
private class MyAsyncTask extends AsyncTask<String, Integer, Double>
{
@Override
protected Double doInBackground (String... params)
{
String datos = value.getText().toString();
// Create a new HttpClient and Post Header
HttpClient httpClient = getNewHttpClient();
HttpPost httppost = new HttpPost("http://myURL.com");
try
{
//.........
return null;
}
protected void onPostExecute (Double result)
{
path = Environment.getExternalStorageDirectory().toString() + "/myDirectory";
File f = new File(path);
File file[] = f.listFiles();
Log.d("Files", "Size: " + file.length);
for (int i = 0; i < file.length; i++)
{
Log.d("Files", "FileName:" + file[i].getName());
etmd5.setText(etmd5.getText() + file[i].getName() + "n");
}
runOnUiThread(new Runnable() {
@Override
public void run() {
File fileArray = new File(path);
ArrayList<File> files = new ArrayList<File>(Arrays.asList(fileArray.listFiles()));
int itemCount = files.size();
tv_files.setText("valor:" + itemCount);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addTextBody("response", "prueba");
for (int i = 0; i < itemCount; i++)
{
builder.addPart("images[]", new FileBody(new File(path + "/" + num_img)));
num_img++;
}
HttpEntity entity = builder.build();
}
});
}
我做了一些不好的事情,但是。。。我不知道如何从目录中获取所有文件来发送ArrayList文件。。。有什么建议吗?
对于我得到的"解释",你想发送一堆文件(意思是file
是一个实际的文件,而不是java.io.File
)。。。因此,您最好阅读这些文件,将它们添加到Zip字节数组中,并在您的帖子中添加一个实体。嗯。。。并且,请阅读文件API,因为第一行显示:An abstract representation of file and directory pathnames.