|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.aitools.programd.util.FileManager
public class FileManager
FileManager provides a standard interface for getting File objects and paths.
| Field Summary | |
|---|---|
static String |
FILE
The string ""file"". |
| Constructor Summary | |
|---|---|
FileManager()
|
|
| Method Summary | |
|---|---|
static File |
checkOrCreate(String path,
String description)
Checks whether a file given by a path exists, and if not, creates it, along with any necessary subdirectories. |
static File |
checkOrCreateDirectory(String path,
String description)
Checks whether a directory given by a path exists, and if not, creates it, along with any necessary subdirectories. |
static String |
getAbsolutePath(String path)
Returns the absolute path. |
static File |
getBestFile(String path)
Gets a file from a given path. |
static File |
getExistingDirectory(String path)
Sames as getExistingFile(java.lang.String) except that it also
checks that the given path is a directory. |
static File |
getExistingFile(String path)
Gets a file from a given path. |
static String |
getFileContents(String path)
Returns the entire contents of a file as a String. |
static FileInputStream |
getFileInputStream(String path)
Opens and returns a FileInputStream for a given path. |
static FileOutputStream |
getFileOutputStream(String path)
Opens and returns a FileOutputStream for a given path. |
static FileWriter |
getFileWriter(String path,
boolean append)
Gets a FileWriter from a given path. |
static URL |
getRootPath()
Returns the root path. |
static URL |
getWorkingDirectory()
Returns the working directory. |
static List<File> |
glob(String path)
Expands a localized file name that may contain wildcards to an array of file names without wildcards. |
static List<File> |
glob(String path,
String workingDirectoryToUse)
Expands a localized file name that may contain wildcards to an array of file names without wildcards. |
static String |
loadFileAsString(File file)
Loads a file into a String. |
static String |
loadFileAsString(String path)
Loads a file into a String. |
static void |
popWorkingDirectory()
Pops a working directory off the stack. |
static void |
pushWorkingDirectory(URL path)
Pushes a new working directory onto the stack. |
static void |
setRootPath(URL url)
Sets the root path. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String FILE
| Constructor Detail |
|---|
public FileManager()
| Method Detail |
|---|
public static void setRootPath(URL url)
url - the root pathpublic static URL getRootPath()
public static File getBestFile(String path)
path - the path for the file
public static File getExistingFile(String path)
throws FileNotFoundException
path - the path for the file (may be absolute or relative to root
directory)
FileNotFoundExceptionpublic static File getExistingDirectory(String path)
getExistingFile(java.lang.String) except that it also
checks that the given path is a directory.
path - the path for the directory (may be absolute or relative to root directory)
public static FileInputStream getFileInputStream(String path)
throws FileNotFoundException
path -
FileNotFoundException - if the file does not exist
public static FileOutputStream getFileOutputStream(String path)
throws FileNotFoundException
path - the path to which to return a stream
FileNotFoundException - if the file does not exist
public static FileWriter getFileWriter(String path,
boolean append)
throws IOException
path - the path for the file (may be absolute or relative to root
directory)append - if true, then bytes will be written to the end
of the file rather than the beginning
IOException - if the specified file is not found or if some other
I/O error occurs
public static String getAbsolutePath(String path)
throws FileNotFoundException
path - the path for the file (may be absolute or relative to root
directory)
FileNotFoundException - if a file with the given path cannot be
located
public static File checkOrCreate(String path,
String description)
path - denoting the file to createdescription - describes what the file is for, for trace messages.
Should fit into a sentence like, "created new
description ". May be null (which will result in
less informative messages).
public static File checkOrCreateDirectory(String path,
String description)
path - denoting the directory to createdescription - describes what the directory is for, for trace
messages. Should fit into a sentence like, "created new
description ". May be null (which will result in
less informative messages).
public static String getFileContents(String path)
path - the path to the file (local file or URL)
public static List<File> glob(String path)
throws FileNotFoundException
path -
FileNotFoundException - if wild card is misused
public static List<File> glob(String path,
String workingDirectoryToUse)
throws FileNotFoundException
Expands a localized file name that may contain wildcards to an array of file names without wildcards. All file separators in the file name must preceed any wildcard.
Adapted, with gratitude, from the JMK project. (Under the GNU LGPL)
path - the path string to globworkingDirectoryToUse - the path to which relative paths should be
considered relative
FileNotFoundException - if wild card is misusedpublic static void pushWorkingDirectory(URL path)
path - the directory pathpublic static void popWorkingDirectory()
public static URL getWorkingDirectory()
public static String loadFileAsString(String path)
throws FileNotFoundException
path - the path to the file
FileNotFoundExceptionpublic static String loadFileAsString(File file)
file - the file
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||