public abstract class IOUtils extends Object
Constructor and Description |
---|
IOUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
cleanDir(String directory)
Empty a directory without deleting it
|
static void |
cp(String sourceFileName,
String destFileName)
Copy a file.
|
static boolean |
exists(String file)
Check if a file exists.
|
static String |
getFileExtension(String name)
Get the extension of a file.
|
static String |
getFileName(String path)
Returns the file name from a full path.
|
static String |
getFileStem(String path) |
static List<URL> |
getListOfFilesInDir(String path) |
static boolean |
isDirectory(String dir)
Check if the argument is a directory.
|
static boolean |
isFile(String file)
Check if this the argument is a file.
|
static String[] |
ls(String directory)
List the contents of a directory.
|
static String[] |
lsDirectories(String directory)
List the directories contained within a directory.
|
static String[] |
lsFiles(String directory)
List the files contained in a directory.
|
static String[] |
lsFiles(String directory,
FilenameFilter filter)
Filters the files contained in a directory.
|
static String[] |
lsFilesRecursive(String directory,
FilenameFilter filter)
Filters the files contained in a directory or in its subdirectory structure.
|
static List<URL> |
lsResources(Class clazz,
String path)
Lists resources that are contained within a path.
|
static List<URL> |
lsResourcesDir(Class clazz,
String path)
Lists resources that are contained within a path.
|
static boolean |
mkdir(String dir)
Create a directory, if it does not exist.
|
static String |
mkTmpDir(String prefix)
Creates a temporary directory and returns its name.
|
static String |
pwd()
Get the current working directory.
|
static <T> T |
readObject(String fileName) |
static <T> T |
readObjectAsResource(Class clazz,
String fileName) |
static boolean |
rm(String file)
Delete a file
|
static boolean |
rmDir(String directory) |
static String |
stripFileExtension(String name)
Remove the extension from the file name.
|
static boolean |
touch(String file)
Create a new empty file.
|
static <T> void |
writeObject(T object,
String fileName) |
public static boolean exists(String file)
public static boolean isFile(String file)
public static boolean isDirectory(String dir)
public static boolean mkdir(String dir)
public static String getFileExtension(String name)
public static String stripFileExtension(String name)
public static String[] ls(String directory) throws IOException
IOException
public static String[] lsFiles(String directory) throws IOException
IOException
public static String[] lsFiles(String directory, FilenameFilter filter) throws IOException
IOException
public static String[] lsFilesRecursive(String directory, FilenameFilter filter) throws IOException
IOException
public static String[] lsDirectories(String directory) throws Exception
Exception
public static String pwd() throws IOException
IOException
public static String mkTmpDir(String prefix) throws IOException
prefix
- The prefix of the temporary directory name. This can be used to specify the
directory where the temporary directory resides.IOException
public static boolean touch(String file) throws IOException
IOException
public static boolean rm(String file) throws IOException
IOException
public static boolean cleanDir(String directory) throws IOException
directory
- The directory to be cleanedIOException
public static boolean rmDir(String directory) throws IOException
IOException
public static void cp(String sourceFileName, String destFileName) throws IOException
IOException
public static List<URL> lsResources(Class clazz, String path) throws URISyntaxException, IOException
NB: This method works only for full file names. If you need to list the files of a
directory contained in the classpath use lsResourcesDir(Class, String)
clazz
- The class whose path is scannedpath
- The name of the resource(s) to be returnedURISyntaxException
IOException
public static List<URL> lsResourcesDir(Class clazz, String path) throws IOException
NB: This method can be used to list the files of a directory contained in the
classpath. However, since it explicitly lists the contents of each classpath resource it is
very slow. If you need a list of specific files (or for directories that are not inside
jars), use lsResources(Class, String)
clazz
- The class whose path is scannedpath
- The name of the resource(s) to be returnedIOException
public static <T> void writeObject(T object, String fileName) throws IOException
IOException
Copyright © 2017. All rights reserved.