안드로이드 개발에 새로운 것이므로 쉬운 일이라면 용서해주세요.디렉토리의 파일을 나열하는 방법은 무엇입니까?
나는 SD 카드의 디렉토리에있는 모든 파일을 가져 와서 회 전자에 표시하고 싶지만 어떻게 작동하는지 알 수 없습니다. 이것은 내가 가지고있는 것이고 심지어 그 중 어떤 것이 좋을지라도 나는 모른다.
//creates this directory if its not there??
File sd = new File("/sdcard/myfolder");
//gets a list of the files
File[] sdDirList = sd.listFiles();
//add them to the spinner array (this makes it crash)
for(int i=0;i<sdDirList.length;i++)
array_spinnerLoad[i] = sdDirList[i].getName();
그래서 나는 어디로 가고 있습니까? 어디에서든 사용하기 쉬운 튜토리얼에 유용한 링크가 있습니까? 그것은이와 충돌 나던하지만, 회 전자의 배열이
을 작성되지File[] sdDirList = sd.listFiles();
if (sdDirList != null)
{
array_spinnerLoad=new String[sdDirList.length];
for(int i=0;i<sdDirList.length;i++)
array_spinnerLoad[i] = sdDirList[i].getName();
}
작은 팁 * (여기에 문제가있는 경우 확실하지 않음) 일반적으로 SD 카드와 같은 경로는 하드 코딩하지 마십시오. 다른 경로가 다른 장치에서 달라지기 때문입니다. ['Environment.getExternalStorageDirectory()'] (http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory())를 대신 사용하십시오. 모든 장치의 기본 대용량 저장 장치에 대한 유효한 경로를 반환합니다. –
넵 (null pointer) 예외 – user1033558