Getting an Absolute Filename Path from a Relative Filename Path

File file = new File("somefile.txt");
											File absPath = file.getAbsoluteFile();

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. ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.