public class FileUtil extends Object
| Constructor and Description |
|---|
FileUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
absoluteFilenameFor(String name)
Return the absolute filename for a given file.
|
static void |
appendToFile(String fn,
String txt)
Append the text to the file.
|
static void |
copyBytesToFile(byte[] src,
File dst)
Copy "src" byte array to "dst" file.
|
static void |
copyBytesToFile(byte[] src,
String dst)
Copy "src" to "dst".
|
static void |
copyFile(String src,
String dst)
Copy "src" to "dst".
|
static void |
copyFileOverTop(String src,
String dst)
Copy "src" to "dst".
|
static void |
createNewFile(String name)
Creates the new file with the specified name.
|
static void |
deleteDir(String name)
Delete the directory.
|
static void |
deleteDirAndContents(String name)
Delete the directory and all its contents.
|
static void |
deleteFile(String name)
Delete file from directory on host.
|
static void |
deleteFilesFromDir(String name)
Delete all files from directory on host.
|
static void |
deleteFilesFromDirRecursive(String name)
Delete all files and directories from directory on host.
|
static Object |
deserialize(byte[] bytes)
Deserialize the object from the specified byte array.
|
static Object |
deserialize(String fn)
Deserialize the object from the specified file.
|
static boolean |
exists(File f)
Answer whether the file exists.
|
static boolean |
exists(String name)
Answer whether the file exists.
|
static boolean |
fileExists(String name)
Answer whether the file exists.
|
static File |
fileForName(String name)
Return the file with the given name, or null if name is null.
|
static String |
filenameFor(String fullname)
Return the filename for a given absolute filename.
|
static String |
getContents(String fn)
Read the file into a string with no newline added.
|
static String |
getContentsWithSpace(String fn)
Read the file into a string with a space where newlines have been.
|
static File |
getFile(File dir,
String fn)
Returns the file in the specified directory, if it exists.
|
static List |
getFiles(File dir,
FileFilter filter,
boolean recursive)
Returns a (possibly empty) list of all files or directories in the
directory that satisfy the filter.
|
static Properties |
getProperties(String fn)
Read the properties.
|
static SortedMap<String,String> |
getPropertiesAsMap(String fn)
Read the properties file into a sorted map.
|
static Properties |
getPropertiesFromResource(String fn)
Returns the properties in a resource.
|
static String |
getText(String fn)
Read the file into a string.
|
static List<String> |
getTextAsList(String fn)
Read the lines of the file into a list.
|
static SortedSet<String> |
getTextAsSet(String fn)
Read the lines of the file into a sorted set.
|
static List<String> |
getTextAsTokens(String fn)
Read the lines of the file into a list of tokens.
|
static boolean |
hasLinesContaining(String fn,
String substring)
Answer whether the file has any lines that contain the substring.
|
static boolean |
isAbsoluteFilename(String name)
Return whether the filename is absolute.
|
static String |
makeAbsolute(String fn,
String defaultPath) |
static Vector |
makeAbsolute(Vector fns,
String defaultPath)
Replace any simple filenames with absolute ones.
|
static void |
mkdir(File dir)
Creates the specified directory and all intervening ones, if they do not
already exist.
|
static void |
mkdir(String dirname)
Creates the specified directory and all intervening ones, if they do not
already exist.
|
static void |
moveFile(String src,
String dst)
Move "src" to "dst".
|
static String |
pathFor(String fullname)
Return the path for a given absolute filename.
|
static String |
readInFile(String fn,
String prefix)
Return the text line starting with the specified prefix.
|
static void |
replaceInFile(String fn,
String prefix,
String newtxt)
Replace the text line starting with the specified prefix with the new text.
|
static boolean |
rmdir(String name,
boolean throwOnFailure)
Removes the directory and all its contents.
|
static byte[] |
serialize(Object obj)
Serialize the specified object to a byte array.
|
static void |
serialize(Object obj,
String fn)
Serialize the object to the specified file.
|
static String |
tmpNameFor(String name)
Return a temporary file name for the specified name.
|
static void |
writeToFile(String fn,
String txt)
Write the text to the file, overwriting if necessary.
|
public static boolean isAbsoluteFilename(String name)
public static File fileForName(String name)
public static String pathFor(String fullname)
public static String absoluteFilenameFor(String name)
public static String filenameFor(String fullname)
public static Vector makeAbsolute(Vector fns, String defaultPath)
public static File getFile(File dir, String fn)
public static List getFiles(File dir, FileFilter filter, boolean recursive)
public static boolean exists(File f)
public static boolean exists(String name)
public static boolean fileExists(String name)
public static String tmpNameFor(String name)
public static void mkdir(String dirname)
public static void mkdir(File dir)
public static void createNewFile(String name) throws IOException
IOException - if the file already exists.public static void deleteFile(String name)
public static boolean rmdir(String name, boolean throwOnFailure)
name - a file or directory to recursively deletethrowOnFailure - specify if an Exeption should be thrown
when an error is encounteredpublic static void deleteDirAndContents(String name)
public static void deleteFilesFromDir(String name)
public static void deleteFilesFromDirRecursive(String name)
public static void deleteDir(String name)
public static void copyFileOverTop(String src, String dst)
public static void copyBytesToFile(byte[] src,
String dst)
public static void copyBytesToFile(byte[] src,
File dst)
throws IOException
IOExceptionpublic static void writeToFile(String fn, String txt)
public static boolean hasLinesContaining(String fn, String substring)
public static String readInFile(String fn, String prefix)
public static void replaceInFile(String fn, String prefix, String newtxt)
public static String getContents(String fn) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic static String getContentsWithSpace(String fn) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic static String getText(String fn) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic static List<String> getTextAsList(String fn) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic static SortedSet<String> getTextAsSet(String fn) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic static List<String> getTextAsTokens(String fn) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic static SortedMap<String,String> getPropertiesAsMap(String fn) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic static Properties getProperties(String fn) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic static Properties getPropertiesFromResource(String fn) throws IOException
IOExceptionpublic static void serialize(Object obj, String fn)
public static Object deserialize(String fn)
public static byte[] serialize(Object obj)
public static Object deserialize(byte[] bytes)
Copyright © 2010-2015 Pivotal Software, Inc. All rights reserved.