如何实现java对本机文件进行分页显示

如题所述

第1个回答  2017-05-02
public Map<String, Object> getFileList(String path, int from, int to) {
Map<String, Object> map = new HashMap<>();
List<String> fileList = new ArrayList<>();
int total = 0;
if(new File(path).exists()){
File[] fileArr = new File(path).listFiles();
if (fileArr != null && fileArr.length > 0) {
total = fileArr.length;
if (to >= fileList.size()) {
to = fileList.size();
}
for (int i = from; i < to; i++) {
fileList.add(fileList.get(i));
}
}
}
map.put("total", total);
map.put("fileList", fileList);
return map;
}

本回答被网友采纳
第2个回答  2018-06-13
public Map<String, Object> getFileList(String path, int from, int to) {
Map<String, Object> map = new HashMap<>();
List<String> fileList = new ArrayList<>();
int total = 0;
if(new File(path).exists()){
File[] fileArr = new File(path).listFiles();
if (fileArr != null && fileArr.length > 0) {
total = fileArr.length;
if (to >= fileArr.length) {
to = fileArr.length;
}
for (int i = from; i < to; i++) {
fileList.add(fileArr[i].getPath());
}
}
}
map.put("total", total);
map.put("fileList", fileList);
return map;
}
相似回答