In this phrase, we get an absolute path for a file for which we specify a relative path. An absolute pathname gives the full path for a file starting from the file system's root directory, i.e. c:\project\book\somefile.txt. A relative pathname specifies a file's name and path relative to the current directory, i.e. somefile.txt if the current directory is c:\project\book. In many cases, a relative pathname consists of only the filename. The getAbsoluteFile() method of the File class returns a File object representing the absolute filename for the file represented by the File object on which it is called. There is a similar method called getAbsolutePath() that returns the absolute path as a String instead of as a File object. The code below shows this method: File file = new File("filename.txt"); String absPath = file.getAbsolutePath(); In this example, absPath would contain the string "c:\project\book\somefile.txt". |