PathHelper

public class PathHelper

It provides some useful method for handling the file path issue. version 1.0.1 - Added getRelativePath(String,String).

Author:Twinsen

Methods

createPath

public static void createPath(String path)

Create the path specified in parameter. This method will create any missing directory from the path.

Throws:
  • IOException

getCanonicalPath

public static String getCanonicalPath(String basePath, String path)

Get the canonical path from the basePath and relative path.

Parameters:
  • basePath
  • path
Throws:
  • IOException
Returns:

the canonical path from the “path”.

getExtension

public static String getExtension(String path)

Get the file extension from the specified path.

Parameters:
  • path – The filepath for getting it’s extension.
Returns:

return the extension of the path. It returns empty string if the path is not directory or file without extension.

getFilename

public static String getFilename(String path)

Get the filename of the particular path. If the filename of the path does not exist, throws IOException.

Parameters:
  • path
Throws:
  • IOException – if the file does not exist or it is a directory.

getRelativePath

public static String getRelativePath(String basePath, String path)

Get the relative path from the canoical basepath and path.

Parameters:
  • basePath
  • path
Throws:
  • IOException

removeExtension

public static String removeExtension(String path)

Remove the file extension from the specified path.

Parameters:
  • path
Returns:

return the path without extension.

renameTo

public static File renameTo(File source, String newName)

Rename the file specified to the new name specified in parameters.

Parameters:
  • source – The source file object.
  • newName – The new name of the object.
Returns:

The new file object for the new path.