如何实现java对本机文件进行分页显示
展开全部
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;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
引用lw_0122的回答:
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;}
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;}
展开全部
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;
}
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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询