1个回答
展开全部
/**
* 获取文件并按文件名称排序
* @param path 初始路径
* @return
*/
public static ArrayList<File> getFilesOrder(String path){
ArrayList<File> filesList = new ArrayList<File>();
if(StrTools.isNull(path)){
return filesList;
}
File file = new File(path);
if(!file.isDirectory()){
return filesList;
};
File[] files = file.listFiles();
if(files == null){
return filesList;
}
File temp;
for(int i = 0; i < files.length;i++) {
for(int j = 0;j < files.length - i -1;j++) {
if(files[j].getName().compareTo(files[j + 1].getName()) > 0) {
temp = files[j];
files[j] = files[j + 1];
files[j + 1] = temp;
}
}
}
return filesList;
}
path传sd卡路径就是了
/**
* 获取sdcard的路径
* sdcard不存在则返回空
* @return
*/
public static String getSDCardPath() {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File sdCard = Environment.getExternalStorageDirectory();
String path = sdCard.getPath();
return path;
}
return null;
}
* 获取文件并按文件名称排序
* @param path 初始路径
* @return
*/
public static ArrayList<File> getFilesOrder(String path){
ArrayList<File> filesList = new ArrayList<File>();
if(StrTools.isNull(path)){
return filesList;
}
File file = new File(path);
if(!file.isDirectory()){
return filesList;
};
File[] files = file.listFiles();
if(files == null){
return filesList;
}
File temp;
for(int i = 0; i < files.length;i++) {
for(int j = 0;j < files.length - i -1;j++) {
if(files[j].getName().compareTo(files[j + 1].getName()) > 0) {
temp = files[j];
files[j] = files[j + 1];
files[j + 1] = temp;
}
}
}
return filesList;
}
path传sd卡路径就是了
/**
* 获取sdcard的路径
* sdcard不存在则返回空
* @return
*/
public static String getSDCardPath() {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File sdCard = Environment.getExternalStorageDirectory();
String path = sdCard.getPath();
return path;
}
return null;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询