Advertisement
iamaamir

SortByFileTypeThenByName

Jul 23rd, 2015
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. /**
  2. @author : Aamir khan
  3. @url : chapter09.blogspot.in
  4.  
  5. Sort Files by type and then by names and vice versa
  6. **/
  7. private static Comparator SortByFileTypeThenByName() {
  8.  
  9.         return Comparator.comparing((File f) -> {
  10.             String probeContentType = null;
  11.             try {
  12.                 probeContentType = Files.probeContentType(f.toPath());
  13.                 if (probeContentType == null) {
  14.                     probeContentType = "probeContentTypeIsNull";
  15.                 }
  16.             } catch (IOException e) {}
  17.             return probeContentType;
  18.         }).thenComparing(File::getName);
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement