Search code examples
javapathjava-6

Alternative to Paths in Java 6?


I want to retrieve the absolute path to the current directory in Java 6, but cannot use Paths.

String currentDirectory = Paths.get(".").toAbsolutePath().normalize().toString();

What is the alternative?


Solution

  • Use new File(".").getAbsolutePath()

    https://docs.oracle.com/javase/7/docs/api/java/io/File.html#getAbsolutePath()

    Returns the absolute abstract pathname denoting the same file or directory as this abstract pathname

    Since: 1.2