마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 질문이요......

0 추천
public class magnifyActivity extends ActionBarActivity  {
 
 TextView text2,text4;
 ArrayList<String> fileList = new ArrayList<String>();
 String path = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
   
@Override
 protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.magnifymain);
 
     text2 = (TextView) findViewById(R.id.text2);
     text4 = (TextView) findViewById(R.id.text4);
 
 
     test b = new test();
     b.execute();
 }
 
public class test extends AsyncTask<String, String, String>{

 String root_sd;
 File file;
 @Override
 protected void onPreExecute(){
     super.onPreExecute();

 }

 @Override
 protected String doInBackground(String... params) {
     root_sd = Environment.getExternalStorageDirectory().toString();
     Log.d("root_sd = ", root_sd);
     file = new File(root_sd);
     File list[] = file.listFiles();
     
     for(int i=0; i<list.length; i++){
      System.out.println("  path " + list + "   " + list.length);
     if(file.isDirectory()){ 
        fileList.add(doInBackground(list[i].getPath()));
        Log.d("file ", list[i].getPath());
        
        this.publishProgress(list[i].getPath());
        
     }
     else{
         fileList.add(list[i].getPath());
         Log.d("file ", list[i].getPath());
         this.publishProgress(list[i].getPath());
     }

         try {
        
             Thread.sleep(100);
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
     }
 return root_sd;
 }



@Override
 protected void onProgressUpdate(String... input){
     super.onProgressUpdate(input);
     text2.setText("/sdcard/emulated/0/"+input[0]);
     text4.setText(input[0].valueOf(text2));
}
}
 
 
 
 여기서 재귀호출을 사용해서.. 디렉토리일때는 안에 데이터가 없는지 확인하려고 하는데요.현재 이상하게...    if(file.isDirectory()){  만 먹히고..
if(file.isFile()){ 안먹히는데 왜그런거죠?....
 
 그리고 재귀호출식으로 바꿀려면 어떻게 바꿔야될까요?

 

related to an answer for: 안드로이드 파일경로..출력
헬프미 (5,430 포인트) 님이 2015년 5월 5일 질문

1개의 답변

0 추천
isFile을 어디서 쓰는지 안나와있어 확인할 수 없지만, isFile은 파일인지 아닌지 구분하는 메소드 입니다.

 

구글에 java 파일 재귀호출 만 쳐도 엄청난 자료가 나옵니다.

http://ra2kstar.tistory.com/133
작전동 (5,890 포인트) 님이 2015년 5월 13일 답변
...