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