How to get a file’s parent folder properly in java?

By W.Zh

In java , file normally is a relative file, which means that these two are different in java:

        File f = new File(“./file1.txt”);
File f1 = new File(“file1.txt”);

f1.getParent() will get an error as it return a null. so how to get parent folder of a file normally by this way: