Directory 생성, file list 가져오기 예제입니다.

여기 예제는 외부 메모리를 엑세스 하기때문에 

os 7.0 이상에서는 system permission 관련 로직을 추가하셔야 가능합니다.


참고 url 

https://developer.android.com/reference/android/os/Environment.html


public static String DIRECTORY_ALARMS = "alarms";

public static String DIRECTORY_DCIM = "DICM";

public static String DIRECTORY_DOCUMENTS = "documents" ;

public static String DIRECTORY_DOWNLOADS = "downloads" ;

public static String DIRECTORY_MOVIES = "movies";

public static String DIRECTORY_MUSIC = "music" ;

public static String DIRECTORY_NOTIFICATIONS = "notifications" ;

public static String DIRECTORY_PICTURES = "pictures" ;

public static String DIRECTORY_PODCASTS = "podcasts" ;

public static String DIRECTORY_RINGTONES = "ringtones" ;


public void getFolderFileList() {
	//internal 
	//File dir = new File(getFilesDir().getAbsolutePath(), "test");
	File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "test");
	if (! dir.isDirectory()){
		if (! dir.mkdirs()){
		}
	}

	String[] str = dir.list();
	for(String st : str) {
		Log.d("test"," st : "+st +" , "+st.endsWith(".gif"));
	}

	File[] files = dir.listFiles();
	for(File f : files) {
		Log.w("test"," f : "+f.getPath() +" , "+f.getPath().endsWith(".gif"));
		Log.i("test"," f : "+f.getName() +" , "+f.getName().endsWith(".gif"));
	}
}


결과화면



+ Recent posts