In a java program, I create a file with
File temp = new File("temp");
temp.createNewFile();
Then for some reason when I write
File pDir = temp.getParentFile();
and pDir is null. I actually want to write
File pDir = temp.getParentFile().getParentFile();
but that throws a null pointer exception.
You need a file with a path for that, try getAbsoluteFile.
File pDir = temp.getAbsoluteFile().getParentFile();
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