Hi,
I was just trying to test whether the Parent Path is exists for any file path or not. Here is my code snippet :
String strFPath="c:/";
String strParentFileStatus="";
File f=new File(strFPath);
if(f.exists())
{
strParentFileStatus=(f.getParentFile().exists()) ? f.getParentFile().toString():"Parent does not exists";
System.out.println(strParentFileStatus);
}
I got the exception at this line :
strParentFileStatus=(f.getParentFile().exists()) ? f.getParentFile().toString():"Parent does not exists";
java.lang.NullPointerException
at javacert50.FileDetails.getFileDetails(IOOperations.java:36)
at javacert50.IOOperations.main(IOOperations.java:133)
According to docs,
getParentFile().exists() Tests whether the file or directory denoted by this abstract pathname exists.So, I think this method returns me the true(parent exists) or false(parent not exists) value instead of NullPointerException.
Any suggestions?