Have some problem with this code. Namely I am getting the message:
Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 2: [E:\Temp\564\324\123.txt]
public static void main(String[] args) throws Exception{
Path sourseFile = Paths.get("E:\\Temp");
Path[] result = searchFile(sourseFile, "123");
for (Path path : result) {
System.out.println(path);
}
}
public static Path[] searchFile (Path path, String fileName)throws Exception{
DirectoryStream<Path> dirStream = Files.newDirectoryStream(path);
ArrayList<Path> temp = new ArrayList<>();
for (Path s : dirStream) {
if (s.toFile().isDirectory()){
temp.add(Paths.get(Arrays.toString(searchFile(s, fileName))));
}
else {
if (s.toAbsolutePath().toString().contains(fileName)){
temp.add(s.toAbsolutePath());
}
}
}
return temp.toArray(Path[]::new);
}
Full trace
Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 2: [E:\Temp\564\324\123.txt] at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92) at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229) at java.base/java.nio.file.Path.of(Path.java:147) at java.base/java.nio.file.Paths.get(Paths.java:69) at s09.Task1.searchFile(Task1.java:28) at s09.Task1.searchFile(Task1.java:28) at s09.Task1.main(Task1.java:13)