I just encountered behavior I do not understand:
Path path = Paths.get("somefile.txt");
System.out.println(path.getAbsolutePath());
System.out.println(path.getParent());
Well, to be honest, I was debugging some code and I evaluated this code on runtime and path was resolved as WindowsPath instance, therefore there was method getAbsolutePath
available.
When I ran the code, parent was null but absolutePath printed the absolute path. So If the object knows absolute path and there is parent directory why does it return null?
you have to give the complete path /home/username/filename.txt instead somefile.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With