|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.senn.magic.util.FileUtils
public final class FileUtils
This class contains useful methods for file modifications.
| Method Summary | |
|---|---|
static int |
childrenCount(File file)
Counts how many children are in the folder. |
static void |
copy(File srcFile,
File destFile)
Copy file (with content) from source to destination |
static boolean |
delete(File toDelete)
Delete a file from the file system |
static boolean |
delete(String path)
Delete a file from the file system |
static boolean |
deleteDir(File dir)
Deletes a folder completely including all his children. |
static int |
directoryCount(File file)
Counts how many actual folders are in the folder. |
static int |
fileCount(File file)
Counts how many actual files are in the folder. |
static byte[] |
getBytesFromFile(File file)
Returns the file ( File object) as an array of bytes. |
static String |
getDirectoryFromFileName(String filename)
Return name of the directory from a provided File's name. |
static String |
getExtension(File file)
Get the extension of a File. |
static String |
getExtension(String path)
Get the extension of a File for the specified path |
static String |
getFileName(String path)
Return name of file without its extension. |
static List<File> |
getFilesInFolder(File folder,
boolean andInSubfolders,
boolean includeSubFoldersInList)
Return the list of files ( File objects) in the specified folder (File object). |
static List<File> |
getFilesInFolder(String folderPath,
boolean andInSubfolders,
boolean includeSubFoldersInList)
Return the list of files ( File objects) in the specified folder path. |
static List<File> |
getFilesInFolderByExtension(File folder,
String extension,
boolean andInSubfolders,
boolean includeSubFoldersInList)
Return the list of files ( File objects), with the specified extension, in
the specified folder |
static List<File> |
getFilesInFolderByExtension(String folderPath,
String extension,
boolean andInSubfolders,
boolean includeSubFoldersInList)
Return the list of files ( File objects), with the specified extension, in
the specified folder path. |
static String |
getParentFolderName(File file)
Returns the name of the containing folder (e.g.: file is located in C:/headFolder/001/fileName.txt, then containing folder = 001) |
static boolean |
hasExtension(String extension,
File file)
Check to see if the file is of type extension (ignoring case sensitivity). |
static void |
move(File srcFile,
File destFile)
Move a file. |
static String |
rename(File file,
String filePath)
Rename a file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static List<File> getFilesInFolder(String folderPath,
boolean andInSubfolders,
boolean includeSubFoldersInList)
File objects) in the specified folder path.
folderPath - path of the folderandInSubfolders - if true, include the files in the sub folders of the folderPathincludeSubFoldersInList - if true, include the sub folders in the list
List - list of files
public static List<File> getFilesInFolder(File folder,
boolean andInSubfolders,
boolean includeSubFoldersInList)
File objects) in the specified folder (File object).
folder - path of the folderandInSubfolders - if true, include the files in the sub folders of the folderPathincludeSubFoldersInList - if true, include the sub folders in the list
List - list of files
public static List<File> getFilesInFolderByExtension(File folder,
String extension,
boolean andInSubfolders,
boolean includeSubFoldersInList)
File objects), with the specified extension, in
the specified folder
folder - folder to scanextension - extension to look forandInSubfolders - if true, include the files in the sub folders of the folder pathincludeSubFoldersInList - if true, include the sub folders in the list
List - list of files
public static List<File> getFilesInFolderByExtension(String folderPath,
String extension,
boolean andInSubfolders,
boolean includeSubFoldersInList)
File objects), with the specified extension, in
the specified folder path.
folderPath - folder to scanextension - extension to look forandInSubfolders - if true, include the files in the sub folders of the folder pathincludeSubFoldersInList - if true, include the sub folders in the list
List - list of files
public static byte[] getBytesFromFile(File file)
throws IOException
File object) as an array of bytes.
file - file to convert
byte[] - an array of bytes
IOException
public static void copy(File srcFile,
File destFile)
throws IOException
srcFile - file to copydestFile - destination folder
IOExceptionpublic static String getExtension(File file)
File.
file - file to get the extension from
String - the extension of a filepublic static String getExtension(String path)
File for the specified path
path - path of the file to get the extension from
String - the extension of a file
public static boolean hasExtension(String extension,
File file)
extension - extension to checkfile - file to check
boolean - true if file has the provided extension, false if it doesn'tpublic static String getFileName(String path)
path - path of the file
String - name of the filepublic static String getDirectoryFromFileName(String filename)
File's name.
filename - name of the file
String - name of the directorypublic static String getParentFolderName(File file)
file - file to get the parent folder from
String - name of the containing folder
public static String rename(File file,
String filePath)
file - old filefilePath - new file with path
String - the new path of the file
public static void move(File srcFile,
File destFile)
throws IOException
srcFile - source filedestFile - destination file
IOException
public static boolean delete(File toDelete)
throws IOException
toDelete - file to delete
boolean true if and only if it succeeded, else false
IOException
public static boolean delete(String path)
throws IOException
path - path of the file to delete
boolean true if and only if it succeeded, else false
IOExceptionpublic static int childrenCount(File file)
file - file representing a folder
int - the children count or -1 if the file is not a folderpublic static int fileCount(File file)
file - file representing a folder
int - the file count or -1 if the file is not a folderpublic static int directoryCount(File file)
file - file representing a folder
int - the folder count or -1 if the file is not a folderpublic static boolean deleteDir(File dir)
dir - directory to delete
boolean - true if everything was deleted successfully,
false if something went wrong
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||