Android   SD卡上有一个文件夹为testimages:
里面的文件为:Frame00020.y
              Frame00021.y
              Frame00022.y
              Frame00023.y
                 .
                 .
                 .
              Frame00957.y
              Frame00958.y文件数据为:DetectFacesBySize(byte[] picdata, int nWidth, int nHeight)
请问如何把文件读入内存,并分配,请给出详细代码,万分感谢,最好留下QQ以便请教。C++是这样写的:for (int i=20; i<958; i++){
sprintf(FileName, "..\\test_images\\Frame%05d.y", i);
pY = readBVImage(FileName, &nWidth, &nHeight);

解决方案 »

  1.   

    用File的list()方法,可以获得testimages下的所有文件名,然后挨个读取
    File file = new File("/sdcard/testimages");
    String[] list = file.list();
             list中为testimages下的所有文件名,可以过滤后缀名来获取想要读取的文件名,然后挨个读取
      

  2.   

    //==android读文件用openFileInput();
    //==读取文件内容
    //Frame00020.y----Frame00958.y
    String str2[]=new String[939]; 
    int count=0;
    for(int i=20;i<959;i++){
    if(i<100){
    InputStream is=openFileInput("Frame000"+i+".y");//每次循环后要不要关流忘了,感觉肯定会报错
    }
            else{
    InputStream is=openFileInput("Frame00"+i+".y");
    }

    byte[] buffer=new byte[2048];
    int byteCount=is.read(buffer);
    str2[count]=new String(buffer,0,byteCount,"utf-8");
    count++;
    }

            //str2[]为读取所有文件的内容,其实我也不太懂,不知道对不对,但我思路是这样的,
    //不对我也没招了,因为几百个文件肯定不能手动读,那会死人的....
    //QQ272647352目前正在学习android