-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinder.java
More file actions
45 lines (35 loc) · 1.17 KB
/
Copy pathFinder.java
File metadata and controls
45 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* **********************************************************************
* Test program to find a file in current or dependent directory
* **********************************************************************
*
*
*
*/
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;
public class Finder {
public static void main(String[] args) throws IOException {
String fn;
if (args.length >0)
fn = args[0];
else
fn = "cam1.py";
Path startingDirectory = Path.of("."); // Current directory
/*
Path p1 = Files.walk(startingDirectory).filter(path -> path.getFileName().toString().equals(fn));
System.out.println("file found at ["+p1+"]");
*/
findFile(startingDirectory, fn)
.ifPresentOrElse(
path -> System.out.println("File found: " + path),
() -> System.out.println("File not found.")
);
}
public static Stream<Path> findFile(Path directory, String fileName) throws IOException {
return Files.walk(directory)
.filter(path -> path.getFileName().toString().equals(fileName));
}
}