0

I want to read the path of a file. All I've found is about the class file, how to read the file or how to save the file in this direction.

But what I want is a method that shows me the path like this:

C:/Users/Administrator/Documents/NetBeansProjects/HashmapDemo/HeaderTemplate

So that i can save this direction in a XML file.

I hope it is understandable what I mean, I tend to write things nobody can understand.

I've tried:

    public static String getCleanPath() {
    ClassLoader classLoader = XmlLoader.class.getClassLoader();
    File classpathRoot = new File(classLoader.getResource("").getPath());

    return classpathRoot.getPath();
}

So far but like I said, it doesn't give me the information I need.

jntme
  • 602
  • 1
  • 5
  • 18
Kyo Akashi
  • 213
  • 1
  • 2
  • 13

1 Answers1

1

Maybe the getAbsoulePath() method is what you are looking for?

public String getAbsolutePath()

Returns the absolute pathname string of this abstract pathname.

If this abstract pathname is already absolute, then the pathname string is simply returned as if by the getPath() method. If this abstract pathname is the empty abstract pathname then the pathname string of the current user directory, which is named by the system property user.dir, is returned. Otherwise this pathname is resolved in a system-dependent way. On UNIX systems, a relative pathname is made absolute by resolving it against the current user directory. On Microsoft Windows systems, a relative pathname is made absolute by resolving it against the current directory of the drive named by the pathname, if any; if not, it is resolved against the current user directory.

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

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Svoice
  • 98
  • 4