I have below code which is working correctly in Java 7. But how can I make it work for Java 6??
List<Map<String, String>> map = new ArrayList<Map<String, String>>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(Path))) { //auto close stream
for (Path path : stream) {
Map<String, String> fileList = new HashMap<>();
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
if (!Files.isDirectory(path)) {
byte[] filepath = path.toFile().toURI().toURL().toString().getBytes("UTF-8");
String encodedPath = DatatypeConverter.printBase64Binary(filepath);
long time = attr.lastModifiedTime().toMillis();
fileList.put("filename", path.getFileName().toString());
fileList.put("date", String.valueOf(time));
fileList.put("path", encodedPath);
map.add(fileList);
}
}
sortArray(map);
} catch (FileNotFoundException e) {
LOGGER.error("Folder not found " + Path);
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
return map;
}
I know try-catch
need to be changed to work in java 6. So can just use like below. However, how do I declare the directory stream? since java 6 not support the diamond operator <>
try{
} catch (){
}