public class

FileUtil

extends Object
java.lang.Object
   ↳ casmi.util.FileUtil

Class Overview

File utility class.

Summary

Fields
public static final String PATH_SEPARATOR The system-dependent path-separator character.
public static final String SEPARATOR The system-dependent default name-separator character, represented as a string for convenience.
Public Constructors
FileUtil()
Public Methods
static void copyFile(File src, File dest)
Copies a file to a new location preserving the file date.
static boolean delete(File file)
Deletes a file.
static boolean exist(String filePath)
Check file existence
static String getSuffix(File file)
Returns a suffix string from a File.
static void moveFile(File src, File dest)
Moves a file from src to dest.
static String searchFilePath(String fileName)
Search an absolute file path from current working directory recursively.
static void touch(File file)
Implements the same behavior as the "touch" utility on Unix.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final String PATH_SEPARATOR

The system-dependent path-separator character. This field is initialized to contain the first character of the value of the system property path.separator. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';'.

public static final String SEPARATOR

The system-dependent default name-separator character, represented as a string for convenience. This string contains a single character. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\\'.

Public Constructors

public FileUtil ()

Public Methods

public static void copyFile (File src, File dest)

Copies a file to a new location preserving the file date.

Parameters
src An existing file to copy, must not be null.
dest The new file, must not be null and exist.
Throws
IOException If copying is failed.

public static boolean delete (File file)

Deletes a file.

Parameters
file A file to delete.
Returns
  • true if the file was deleted, otherwise false.

public static boolean exist (String filePath)

Check file existence

Returns
  • Return true if the file is exist, otherwise return false

public static String getSuffix (File file)

Returns a suffix string from a File.

Parameters
file The file to know the suffix.
Returns
  • A suffix string

public static void moveFile (File src, File dest)

Moves a file from src to dest. This method is equals to "copy -> delete."

Parameters
src An existing file to move, must not be null.
dest The destination file, must not be null and exist.
Throws
IOException If moving is failed.

public static String searchFilePath (String fileName)

Search an absolute file path from current working directory recursively.

Parameters
fileName file name to search.
Returns
  • an absolute file path.

public static void touch (File file)

Implements the same behavior as the "touch" utility on Unix. It creates a new file with size 0 byte or, if the file exists already, it is opened and closed without modifying it, but updating the file date and time.

Parameters
file The file to "touch."
Throws
FileNotFoundException If the file is not found.