Class Information
Package: com.onepg.util
Class Name: FileUtil
Description
Method List
getOsTemporaryPath
public String getOsTemporaryPath()
- 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)
- 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
replaceTypeMark
public String replaceTypeMark(String path, String typeMark)
- Replaces the extension of the file path.
Parameters
| Name | Type | Description |
|---|---|---|
path |
String |
file path |
typeMark |
String |
the extension to replace with |
Return Value
String - the file path
convOsPath
public String convOsPath(String 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)
- 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)
Parameters
| Name | Type | Description |
|---|---|---|
checkPath |
String |
path to check |
Return Value
boolean - true if exists
existsParent
public boolean existsParent(String checkPath)
Parameters
| Name | Type | Description |
|---|---|---|
checkPath |
String |
path to check |
Return Value
boolean - true if exists
isDirectory
public boolean isDirectory(String checkPath)
Parameters
| Name | Type | Description |
|---|---|---|
checkPath |
String |
path to check |
Return Value
boolean - true if a directory
getFileName
public String getFileName(String fullPath)
Parameters
| Name | Type | Description |
|---|---|---|
fullPath |
String |
full path |
Return Value
String - the file name only
getParentPath
public String getParentPath(String fullPath)
- Returns
nullif the parent directory does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
fullPath |
String |
full path |
Return Value
String - the parent directory path
getFileModifiedDateTime
public String getFileModifiedDateTime(String fullPath)
Parameters
| Name | Type | Description |
|---|---|---|
fullPath |
String |
full path |
Return Value
String - the file modified date-time (yyyyMMddHHmmss)
splitTypeMark
public String[] splitTypeMark(String fileName)
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)
trimTypeMark
public String trimTypeMark(String fileName)
Parameters
| Name | Type | Description |
|---|---|---|
fileName |
String |
file name or full path |
Return Value
String - the part before the extension (does not include the dot)
getTypeMark
public String getTypeMark(String fileName)
Parameters
| Name | Type | Description |
|---|---|---|
fileName |
String |
file name or full path |
Return Value
String - the extension (does not include the dot)
getFileList
public String[] getFileList(String dirPath, String typeMark, String prefixMatch, String middleMatch, String suffixMatch)
- 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
String[] - the file path (absolute path) array
move
public File move(String srcFilePath, String destFilePath)
Parameters
| Name | Type | Description |
|---|---|---|
srcFilePath |
String |
source file path |
destFilePath |
String |
destination file path (directory specification allowed) |
Return Value
File - the destination file object
See Also
move
public File move(File srcFile, File destFile)
- 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)
Parameters
| Name | Type | Description |
|---|---|---|
srcFilePath |
String |
source file path |
destFilePath |
String |
destination file path (directory specification allowed) |
Return Value
File - the destination file object
See Also
copy
public File copy(File srcFile, File destFile)
- 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)
- Returns
falseif 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)
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)
Parameters
| Name | Type | Description |
|---|---|---|
dirPath |
String |
directory path |
Return Value
boolean - false if it already exists
zip
public void zip(String srcPath, String fileNameCharset, String zipPath)
Parameters
| Name | Type | Description |
|---|---|---|
srcPath |
String |
source file path |
fileNameCharset |
String |
file name character set |
zipPath |
String |
zip file path |
zip
public void zip(List<String> srcPaths, String fileNameCharset, String zipPath)
Parameters
| Name | Type | Description |
|---|---|---|
srcPaths |
List<String> |
source file path list |
fileNameCharset |
String |
file name character set |
zipPath |
String |
zip file path |
unzip
public String[] unzip(String zipPath, String destDirPath)
Parameters
| Name | Type | Description |
|---|---|---|
zipPath |
String |
zip file path |
destDirPath |
String |
destination directory path for extraction |
Return Value
String[] - the array of extracted file names