Catch Invalid path exception
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Test {
public static void main(String[] args) {
try {
Path path = Paths.get("/home\0", "docs", "users.txt");
System.out.println("Absolute path: " + path.toAbsolutePath());
} catch (InvalidPathException ex) {
System.out.println("Bad path: [" + ex.getInput() + "] at position "
+ ex.getIndex());
}
}
}
Related examples in the same category