FileUtil

Framework Components [com.onepg.util]

← Back to Class List

Class Information

Package: com.onepg.util

Class Name: FileUtil

Description

File operations utility class.

Method List

getOsTemporaryPath

public String getOsTemporaryPath()
Retrieves the OS temporary directory path.
  • Specifically, returns the path of the Java java.io.tmpdir system property.

Return Value

String - the OS temporary directory path

joinPath

public String joinPath(String... paths)
Joins file paths.
  • Passing blank at the end of arguments returns a path ending with / or \.
  • The separator is the OS-appropriate character.

Parameters

Name Type Description
paths String... file paths (multiple specification)

Return Value

String - the file path

convOsPath

public String convOsPath(String path)
Converts to OS path.
  • The separator is replaced with the OS-appropriate character.

Parameters

Name Type Description
path String file path

Return Value

String - the file path

convAbsolutePath

public String convAbsolutePath(String path)
Converts to absolute path.
  • Relative paths are converted to absolute paths.
  • The separator is replaced with the OS-appropriate character.

Parameters

Name Type Description
path String relative path

Return Value

String - the absolute path

exists

public boolean exists(String checkPath)
Checks if a file exists (directories are also acceptable).

Parameters

Name Type Description
checkPath String path to check

Return Value

boolean - true if exists

existsParent

public boolean existsParent(String checkPath)
Checks if the parent directory exists (directories are also acceptable).

Parameters

Name Type Description
checkPath String path to check

Return Value

boolean - true if exists

getFileName

public String getFileName(String fullPath)
Retrieves the file name from the full path (directories are also acceptable).

Parameters

Name Type Description
fullPath String full path

Return Value

String - the file name only

getParentPath

public String getParentPath(String fullPath)
Retrieves the parent directory path from the full path (directories are also acceptable).

Parameters

Name Type Description
fullPath String full path

Return Value

String - the parent directory path

getFileModifiedDateTime

public String getFileModifiedDateTime(String fullPath)
Retrieves the file modified date-time.

Parameters

Name Type Description
fullPath String full path

Return Value

String - the file modified date-time (yyyyMMddHHmmss)

splitFileTypeMark

public String[] splitFileTypeMark(String fileName)
Splits file name or full path into extension and the rest.

Parameters

Name Type Description
fileName String file name or full path

Return Value

String[] - the string array {part before extension, extension} (neither includes the dot)

getFileList

public List<String> getFileList(String dirPath, String typeMark, String prefixMatch, String middleMatch, String suffixMatch)
Retrieves the file path (absolute path) list.
  • File name and extension search strings are case-insensitive.

Parameters

Name Type Description
dirPath String target directory path
typeMark String search extension (optional) null if omitted ※ dot character not required
prefixMatch String search file name prefix match (optional) null if omitted
middleMatch String search file name middle match (optional) null if omitted
suffixMatch String search file name suffix match (optional) null if omitted

Return Value

List<String> - the file path (absolute path) list

move

public File move(String srcFilePath, String destFilePath)
Moves a file.

Parameters

Name Type Description
srcFilePath String source file path
destFilePath String destination file path (directory specification allowed)

Return Value

File - the destination file object

move

public File move(File srcFile, File destFile)
Moves a file.
  • If the destination is a directory specification, the file name will be the same as the source.

Parameters

Name Type Description
srcFile File source file
destFile File destination file (directory specification allowed)

Return Value

File - the destination file object

copy

public File copy(String srcFilePath, String destFilePath)
Copies a file.

Parameters

Name Type Description
srcFilePath String source file path
destFilePath String destination file path (directory specification allowed)

Return Value

File - the destination file object

copy

public File copy(File srcFile, File destFile)
Copies a file.
  • If the destination is a directory specification, the file name will be the same as the source.

Parameters

Name Type Description
srcFile File source file
destFile File destination file (directory specification allowed)

Return Value

File - the destination file object

delete

public boolean delete(String deleteFilePath)
Deletes a file.
  • Returns false if the file does not exist.

Parameters

Name Type Description
deleteFilePath String file path to delete

Return Value

boolean - false if the file does not exist

delete

public boolean delete(File deleteFile)
Deletes a file.

Parameters

Name Type Description
deleteFile File file to delete

Return Value

boolean - false if the file does not exist

See Also

makeDir

public boolean makeDir(String dirPath)
Creates a directory.

Parameters

Name Type Description
dirPath String directory path

Return Value

boolean - false if it already exists