Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Folder 1
- Folder 2
- Folder 3
- Folder 4
- Folder 5
- Folder 6
- nfiles.txt....
- MyFile.txt
- xfile.txt
- filesInFolder4....
- filesInFolder3...
- .....
- try (Stream<Path> stream = Files.find(Paths.get("Folder 1"), 5,
- (path, attr) -> path.getFileName().toString().equals("Myfile.txt") )) {
- System.out.println(stream.findAny().isPresent());
- } catch (IOException e) {
- e.printStackTrace();
- }
- // Finding a file upto x level in File Directory using NIO Files.find
- Path start = Paths.get("/Users/***/Documents/server_pull");
- int maxDepth = 5;
- try(Stream<Path> stream = Files.find(start,
- maxDepth,
- (path, attr) -> String.valueOf(path).endsWith(".json"))){
- String fileName = stream
- .sorted()
- .map(String::valueOf)
- .filter((path) -> {
- //System.out.println("In Filter : "+path);
- return String.valueOf(path).endsWith("system_health_12_55_TestServer.json");
- })
- .collect(Collectors.joining());
- System.out.println("fileName : "+fileName);
- }catch(Exception e){
- e.printStackTrace();
- }
- // Finding a file upto x level in File Directory using NIO Files.walk
- Path startWalk = Paths.get("/Users/***/Documents/server_pull");
- int depth = 5;
- try( Stream<Path> stream1 = Files.walk(startWalk,
- depth)){
- String walkedFile = stream1
- .map(String::valueOf)
- .filter(path -> {
- return String.valueOf(path).endsWith("system_health_12_55_TestServer.json");
- })
- .sorted()
- .collect(Collectors.joining());
- System.out.println("walkedFile = "+walkedFile);
- }catch(Exception e){
- e.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement