0

我正在尝试将文件路径加载到字符串数组(路径)中,但我被卡住了。这是我的代码:

public class MainActivity extends ListActivity{

String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Video/";

String[] videoFileList = {

        path,

};

public class MyThumbnaildapter extends ArrayAdapter<String>{

    public MyThumbnaildapter(Context context, int textViewResourceId,
            String[] objects) {
        super(context, textViewResourceId, objects);
        // TODO Auto-generated constructor stub
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        View row = convertView;
        if(row==null){
            LayoutInflater inflater=getLayoutInflater();
            row=inflater.inflate(R.layout.row, parent, false);
        }

        ImageView imageThumbnail = (ImageView)row.findViewById(R.id.Thumbnail);

        Bitmap bmThumbnail;
        bmThumbnail = ThumbnailUtils.createVideoThumbnail(videoFileList[position], Thumbnails.MINI_KIND);
        imageThumbnail.setImageBitmap(bmThumbnail);

        return row;
    }

}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new MyThumbnaildapter(MainActivity.this, R.layout.row, videoFileList));
}

}

我正在尝试加载视频路径。我可以加载一个特定的文件,但不能加载目录中的所有文件。任何帮助将不胜感激。谢谢!

4

2 回答 2

3

看看File.list()。创建一个File包含文件路径的对象。 list()将返回一个数组String

按要求举例。

File pathToFiles = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Video/");

String[] videoFileList = pathToFiles.list();
于 2013-09-12T23:33:44.517 回答
0

要遍历给定目录的文件,请使用

new File(path).listFiles()

或一些新的 Java 7 API,例如:

Path dir = new File(path).toPath();     
DirectoryStream<Path> directoryStream = Files.newDirectoryStream(dir);
于 2013-09-12T23:41:22.633 回答