クラス情報
パッケージ: com.onepg.util
クラス名: FileUtil
説明
ファイル操作ユーティリティクラス.
メソッド一覧
getOsTemporaryPath
public String getOsTemporaryPath()
OS一時ディレクトリパス取得.
- 具体的には Java の java.io.tmpdir システムプロパティのパスを返す。
戻り値
String - OS一時ディレクトリパス
joinPath
public String joinPath(String... paths)
ファイルパス結合.
- 引数の最後にブランクを渡すと / または \ 終わりのパスを返す。
- 区切文字は OS に沿った文字となる。
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
paths |
String... |
ファイルパス(複数指定) |
戻り値
String - ファイルパス
convOsPath
public String convOsPath(String path)
OSパス変換.
- 区切文字が OS に沿った文字に置換される。
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
path |
String |
ファイルパス |
戻り値
String - ファイルパス
convAbsolutePath
public String convAbsolutePath(String path)
絶対パス変換.
- 相対パスがあれば絶対パスに変換される。
- 区切文字が OS に沿った文字に置換される。
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
path |
String |
相対パス |
戻り値
String - 絶対パス
exists
public boolean exists(String checkPath)
ファイル存在確認(ディレクトリも可).
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
checkPath |
String |
確認パス |
戻り値
boolean - 存在する場合は true
existsParent
public boolean existsParent(String checkPath)
親ディレクトリ存在確認(ディレクトリも可).
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
checkPath |
String |
確認パス |
戻り値
boolean - 存在する場合は true
getFileName
public String getFileName(String fullPath)
フルパスからファイル名取得(ディレクトリも可).
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
fullPath |
String |
フルパス |
戻り値
String - ファイル名のみ
getParentPath
public String getParentPath(String fullPath)
フルパスから親ディレクトリパス取得(ディレクトリも可).
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
fullPath |
String |
フルパス |
戻り値
String - 親ディレクトリパス
getFileModifiedDateTime
public String getFileModifiedDateTime(String fullPath)
ファイル更新日時取得.
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
fullPath |
String |
フルパス |
戻り値
String - ファイル更新日時(yyyyMMddHHmmss)
splitFileTypeMark
public String[] splitFileTypeMark(String fileName)
ファイル名またはフルパスを拡張子とそれ以外に分割.
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
fileName |
String |
ファイル名またはフルパス |
戻り値
String[] - 文字配列{拡張子より前の部分、拡張子}(いずれもドットは含まない)
getFileList
public List<String> getFileList(String dirPath, String typeMark, String prefixMatch, String middleMatch, String suffixMatch)
ファイルパス(絶対パス)リスト取得.
- ファイル名、拡張子の検索文字は大文字小文字を区別しない。
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
dirPath |
String |
対象ディレクトリパス |
typeMark |
String |
検索拡張子(省略可能)省略した場合は null ※ドット文字不要 |
prefixMatch |
String |
検索ファイル名 前方一致(省略可能)省略した場合は null |
middleMatch |
String |
検索ファイル名 中間一致(省略可能)省略した場合は null |
suffixMatch |
String |
検索ファイル名 後方一致(省略可能)省略した場合は null |
戻り値
List<String> - ファイルパス(絶対パス)リスト
move
public File move(String srcFilePath, String destFilePath)
ファイル移動.
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
srcFilePath |
String |
移動元ファイルパス |
destFilePath |
String |
移動先ファイルパス(ディレクトリ指定可) |
戻り値
File - 移動先ファイルオブジェクト
関連項目
move
public File move(File srcFile, File destFile)
ファイル移動.
- 移動先がディレクトリ指定の場合、ファイル名は移動元と同じになる。
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
srcFile |
File |
移動元ファイル |
destFile |
File |
移動先ファイル(ディレクトリ指定可) |
戻り値
File - 移動先ファイルオブジェクト
copy
public File copy(String srcFilePath, String destFilePath)
ファイルコピー.
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
srcFilePath |
String |
コピー元ファイルパス |
destFilePath |
String |
コピー先ファイルパス(ディレクトリ指定可) |
戻り値
File - コピー先ファイルオブジェクト
関連項目
copy
public File copy(File srcFile, File destFile)
ファイルコピー.
- コピー先がディレクトリ指定の場合、ファイル名はコピー元と同じになる。
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
srcFile |
File |
コピー元ファイル |
destFile |
File |
コピー先ファイル(ディレクトリ指定可) |
戻り値
File - コピー先ファイルオブジェクト
delete
public boolean delete(String deleteFilePath)
ファイル削除.
- ファイルが無ければ
falseを返す。
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
deleteFilePath |
String |
削除ファイルパス |
戻り値
boolean - ファイルが無い場合は false
delete
public boolean delete(File deleteFile)
ファイル削除.
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
deleteFile |
File |
削除ファイル |
戻り値
boolean - ファイルが無い場合は false
関連項目
makeDir
public boolean makeDir(String dirPath)
ディレクトリ作成.
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
dirPath |
String |
ディレクトリパス |
戻り値
boolean - 既に存在する場合は false