Android中遍历文件夹、比较文件类型测试

package casper.test;

import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class TestGetFileActivity extends Activity {
    /** Called when the activity is first created. */
	private static final String bookDirectory = "/sdcard/files/";
	private ArrayList fileList ;
	 private void getAllFiles(File directory){  
   	  
   	  File files[] = directory.listFiles();  
   	    
   	  if(files != null)
   	 {
   	  for(File f:files)
   	  {  
   	    
   	      if(f.isDirectory())
   	      {  
   	          getAllFiles(f);  
   	      }  
   	      else
   	      {  
   	    	  
   	          this.fileList.add(f);  
   	      }  
   	  }
   	 }
   	}
   
	private Boolean getBookType(File f)
	{    
		   String end = f    
		       .getName()    
		       .substring(f.getName().lastIndexOf(".") + 1,    
		           f.getName().length()).toLowerCase();       
		   if (end.equals("rmvb"))  
			   return Boolean.TRUE;
		   else
			   return Boolean.FALSE;
		   
		 
	}  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        fileList = new ArrayList();
        
		getAllFiles(new File(bookDirectory)); 
		for (int i = 0; i < fileList.size(); i++) 
		{
			 String path  = fileList.get(i).toString();
			 Log.v("aaa",path);
           if(getBookType(new File(path))==Boolean.TRUE)
           {
        	   String tempBookName = path.substring(path.lastIndexOf("/")+1,path.length());
        	   Log.v("aaa",tempBookName);
           }
		}
    }
    
   
}


你可能感兴趣的:(android,string,file,path,class,null,Android)