Get your own Java server
import java.io.File;

public class Main {
  public static void main(String[] args) {
    File myFile = new File("myFolder/filename.txt");
    System.out.println(myFile.getParent());
    File otherFile = new File("filename.txt");
    System.out.println(otherFile.getParent());
  }
}

              
myFolder
null