public class FileUtils
extends java.lang.Object
Constructor and Description |
---|
FileUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
absolutePath(java.lang.String path) |
static void |
closeInputStream(java.io.DataInputStream di)
Closes the given input stream.
|
static void |
closeOutputStream(java.io.DataOutputStream dos)
Closes the given output stream.
|
static void |
closeReader(java.io.BufferedReader br)
closes the given reader
|
static void |
closeWriter(java.io.PrintWriter pw)
closes the given writer
|
static java.lang.String |
convertFromVirtualName(java.lang.String fileName)
Convert machine independant form to actual fileName
|
static java.lang.String |
convertToVirtualName(java.lang.String fileName)
Convert the given fileName into a machine independant form by making use of the environment variables to set up
relative paths etc.
|
static boolean |
copyFile(java.lang.String loc1,
java.lang.String loc2,
int mode)
As copyFile except that it doesn't confirm on replacing a file.
|
static boolean |
copyFile(java.lang.String loc1,
java.lang.String loc2,
int mode,
boolean confirmOnReplace)
Copies the file from the first location to the second.
|
static java.util.List<java.io.File> |
copyFilesRecursive(java.io.File src,
java.io.File dest)
Copies files and directories recursively.
|
static java.lang.String |
correctURL(java.lang.String file)
Converts a URL address which may have machine dependant path separators contained within it to an appropraite URL
address e.g.
|
static java.io.DataInputStream |
createInputStream(java.lang.String name)
Creates a reader for a specified local or networked binary file.
|
static java.io.DataOutputStream |
createOutputStream(java.lang.String name)
Creates an output stream for a specified local or networked binary file.
|
static java.io.BufferedReader |
createReader(java.lang.String name)
creates a buffered reader for a specified local or networked text file.
|
static java.io.BufferedReader |
createReader(java.net.URL url)
creates a buffered reader for a URL
|
static java.io.PrintWriter |
createWriter(java.lang.String name)
creates a buffered writer for a specified local or networked text file.
|
static java.io.PrintWriter |
createWriter(java.lang.String name,
boolean append)
creates a buffered writer for a specified local file, with an option to append.
|
static java.io.PrintWriter |
createWriter(java.net.URL url)
Creates a buffered writer to a specific URL.
|
static void |
deleteFile(java.lang.String loc)
Deletes the file at the given file location.
|
static void |
deleteFiles(java.io.File parent,
boolean incParent)
deletes files recursively.
|
static boolean |
fileExists(java.lang.String name)
return true if the specified file (or Directory) exists either on a network or a local server.
|
static java.lang.String |
formatThrowable(java.lang.Throwable t) |
static java.applet.AudioClip |
getAudioClip(java.lang.String audioFile)
Loads in a sound file from the internet or local disk.
|
static java.applet.AudioClip |
getAudioClip(java.net.URL audioLoc)
Loads in a sound file from the specified internet location.
|
static java.lang.String |
getFileNameNoSuffix(java.lang.String fullName) |
static java.awt.Image |
getImage(java.lang.String imageName)
Loads in an image from the internet or local disk.
|
static java.applet.AudioClip |
getSystemAudioClip(java.lang.String audioFile)
Loads in a Triana system sound file via the internet (if it is an applet) or local disk.
|
static java.awt.Image |
getSystemImage(java.lang.String imageName)
Loads in a triana system image from the internet or local disk.
|
static javax.swing.ImageIcon |
getSystemImageIcon(java.lang.String imageName)
Loads in a triana system image icon from the internet or local disk.
|
static boolean |
isDirectory(java.lang.String loc)
Determines whether the file specified is a directory.
|
static boolean |
isDirectory(java.net.URL loc)
Determines whether the internet location and file specified is in fact a directory.
|
static boolean |
isOnInternet(java.lang.String fileOrPath)
Determines whether the given path or file is an internet address or not
|
static boolean |
isParent(java.lang.String parent,
java.lang.String child)
Checks whether the
child is contained by the |
static Listing |
listAllFiles(java.lang.String searchdir,
java.lang.String searchFilter,
boolean recurseDirs)
Gets a Listing Object for the given directory, the given searchstring (i.e.
|
static java.lang.String[] |
listDir(java.lang.String dir)
returns a list of file names in the given directory or returns null if the directory is empty or if it does not
exist.
|
static Listing |
listDir(java.lang.String dir,
boolean recurse)
Finds all file names in the specified directory and in all directories lower down in the tree.
|
static Listing |
listDir(java.net.URL dir,
boolean recurse)
Finds all file names in the specified directory and in all directories lower down in the tree.
|
static Listing |
listDirNames(java.lang.String searchdir,
java.lang.String searchFilter,
boolean recurseDirs)
Gets a Listing Object for the given directory, the given searchstring (i.e.
|
static java.io.File[] |
listEndsWith(java.lang.String baseDir,
java.lang.String endsWith) |
static java.io.File[] |
listEndsWith(java.lang.String baseDir,
java.lang.String[] endsWith,
java.lang.String[] excludedir) |
static java.io.File[] |
listEndsWith(java.lang.String baseDir,
java.lang.String endsWith,
java.lang.String[] excludedir) |
static Listing |
listFileNames(java.lang.String searchdir,
java.lang.String searchFilter,
boolean recurseDirs)
Gets a Listing Object for the given directory, the given searchstring (i.e.
|
static java.util.Vector<java.lang.String> |
listInternetDirectory(java.net.URL loc)
Lists the filenames and directories within a URL if that URL is a directory
|
static java.lang.String |
nextNonEmptyLine(java.io.BufferedReader br)
Skips the empty lines in a file and returns the next non-empty line or null if the end of the file is reached.
|
static java.util.Vector<java.lang.String> |
nextNonEmptySplitLine(java.io.BufferedReader br)
Skips the empty lines in a file and returns the next non-empty line or null if the end of the file is reached.
|
static void |
playSystemAudio(java.lang.String audioFile)
Plays a Triana system sound file by loading it across the internet (if Triana is an applet)or local disk.
|
static java.util.Vector<java.lang.String> |
readAndSplitFile(java.io.BufferedReader br)
This function splits the file into a vector of Strings, each item in the vector representing one line.
|
static java.util.Vector<java.lang.String> |
readAndSplitFile(java.lang.String fileName)
This function splits the file into a vector of Strings, each item in the vector representing one line.
|
static java.util.Vector<java.lang.String> |
readAndSplitLine(java.io.BufferedReader br)
This function splits the next line createTool from the specified BufferReader into a vector of Strings contained
within the line.
|
static java.lang.String |
readFile(java.io.BufferedReader br)
Reads all the file pointed to by the given reader into the returned string.
|
static java.lang.String |
readFile(java.lang.String filename)
Reads the file specified by the given Filename and puts it into a string.
|
static boolean |
rename(java.io.File src,
java.io.File dest) |
static java.util.Vector<java.lang.String> |
splitLine(java.lang.String line)
This function splits the line into a vector of Strings separated by spaces.
|
static java.util.Vector |
splitPath(java.lang.String path)
This function splits up the CLASSPATH and the TOOLBOXES environment variables into the various specified paths.
|
static void |
writeToFile(java.lang.String name,
java.lang.String contents)
Write the specified String to the file
|
static void |
writeToFile(java.lang.String name,
java.lang.String contents,
boolean append)
Write the specified String to the file with option to append
|
static void |
writeToFile(java.lang.String name,
java.util.Vector<java.lang.String> contents)
Write the specified StringVector to the file, writing each element on a separate line
|
public static final int ASCII
public static final int BINARY
public static void deleteFiles(java.io.File parent, boolean incParent) throws java.io.FileNotFoundException
parent
- file to delete. If this is a directory then any children are deleted.incParent
- boolean that determines if the parent file is also deleted.java.io.FileNotFoundException
public static java.lang.String formatThrowable(java.lang.Throwable t)
public static boolean rename(java.io.File src, java.io.File dest)
public static java.util.List<java.io.File> copyFilesRecursive(java.io.File src, java.io.File dest) throws java.io.IOException
src
- the source file to copy. Can be a file or a directory.dest
- the destination to copy to. Can be a file or directory.java.io.FileNotFoundException
- if src does not existjava.io.IOException
- if src is a directory and dest exists and is not a directory, or an IO
error occurs.public static void deleteFile(java.lang.String loc)
public static boolean isOnInternet(java.lang.String fileOrPath)
public static boolean isDirectory(java.lang.String loc)
public static boolean isParent(java.lang.String parent, java.lang.String child)
child is contained by the parent
directory.
parent
- String representing the parent directorychild
- String representing the child file or directoryparent
is not a directory, or parent
equals child
,
True if and only if child
is contained in parent
.public static java.lang.String correctURL(java.lang.String file)
public static boolean isDirectory(java.net.URL loc)
exists on the first line of the html file which is the typical thing included on the first line if a directory is given to a serverIndex Of .....
public static java.util.Vector<java.lang.String> listInternetDirectory(java.net.URL loc)
public static boolean copyFile(java.lang.String loc1, java.lang.String loc2, int mode)
public static boolean copyFile(java.lang.String loc1, java.lang.String loc2, int mode, boolean confirmOnReplace)
public static java.io.PrintWriter createWriter(java.lang.String name)
name
- the name of the file you wish to make a writer for.public static java.io.PrintWriter createWriter(java.net.URL url)
url
- the name of the file you wish to make a writer forpublic static java.io.PrintWriter createWriter(java.lang.String name, boolean append)
name
- the name of the file you wish to make a writer for.public static java.io.BufferedReader createReader(java.lang.String name) throws java.io.IOException
name
- the name of the file you wish to make a reader for.java.io.IOException
public static java.io.BufferedReader createReader(java.net.URL url)
url
- the name of the file you wish to make a reader for.public static boolean fileExists(java.lang.String name)
name
- the name of the file.public static void closeReader(java.io.BufferedReader br)
br
- the reader to close.public static void closeWriter(java.io.PrintWriter pw)
pw
- the writer to close.public static void writeToFile(java.lang.String name, java.lang.String contents)
public static void writeToFile(java.lang.String name, java.lang.String contents, boolean append)
public static void writeToFile(java.lang.String name, java.util.Vector<java.lang.String> contents)
public static java.io.DataInputStream createInputStream(java.lang.String name) throws java.io.IOException
name
- the name of the file you wish to make a reader for.java.io.IOException
public static java.io.DataOutputStream createOutputStream(java.lang.String name)
name
- the name of the file you wish to make an output stream for.public static void closeOutputStream(java.io.DataOutputStream dos)
public static void closeInputStream(java.io.DataInputStream di)
public static java.applet.AudioClip getAudioClip(java.net.URL audioLoc)
public static java.applet.AudioClip getAudioClip(java.lang.String audioFile)
public static java.applet.AudioClip getSystemAudioClip(java.lang.String audioFile)
public static void playSystemAudio(java.lang.String audioFile)
public static java.awt.Image getImage(java.lang.String imageName)
getSystemImage(java.lang.String)
public static javax.swing.ImageIcon getSystemImageIcon(java.lang.String imageName)
public static java.awt.Image getSystemImage(java.lang.String imageName)
public static java.lang.String getFileNameNoSuffix(java.lang.String fullName)
public static java.util.Vector splitPath(java.lang.String path)
public static java.util.Vector<java.lang.String> readAndSplitLine(java.io.BufferedReader br)
public static java.util.Vector<java.lang.String> nextNonEmptySplitLine(java.io.BufferedReader br)
public static java.lang.String nextNonEmptyLine(java.io.BufferedReader br) throws java.io.IOException
java.io.IOException
readAndSplitLine(java.io.BufferedReader)
public static java.util.Vector<java.lang.String> splitLine(java.lang.String line)
public static java.lang.String readFile(java.io.BufferedReader br)
For example, to open, createTool all, and close a file you type :-
String template = FileUtils.readFile(FileUtils.createReader(fileName));
public static java.lang.String readFile(java.lang.String filename)
public static java.util.Vector<java.lang.String> readAndSplitFile(java.io.BufferedReader br)
public static java.util.Vector<java.lang.String> readAndSplitFile(java.lang.String fileName)
public static java.lang.String convertToVirtualName(java.lang.String fileName)
public static java.lang.String convertFromVirtualName(java.lang.String fileName)
public static Listing listFileNames(java.lang.String searchdir, java.lang.String searchFilter, boolean recurseDirs)
The searchFilter can be any unix style (or DOS style) search expression when using ls or dir. This can also be a file, directory or null. If its a file then this class can be used to determine whether the file exists or not (i.e. if fileFound() == 0 or exists() == false then the file does not exist. If searchFilter is a directory then the directory is listed (if it exists) and if it is set to null then the search is based on the first argument (i.e. the searchdir). This is useful for just lsiting the contents of the directory.
The searchdir can contain "./" or "../" (unix) or ".\" "..\" in dos.public static Listing listDirNames(java.lang.String searchdir, java.lang.String searchFilter, boolean recurseDirs)
The searchFilter can be any unix style (or DOS style) search expression when using ls or dir. This can also be a file, directory or null. If its a file then this class can be used to determine whether the file exists or not (i.e. if fileFound() == 0 or exists() == false then the file does not exist. If searchFilter is a directory then the directory is listed (if it exists) and if it is set to null then the search is based on the first argument (i.e. the searchdir). This is useful for just lsiting the contents of the directory.
The searchdir can contain "./" or "../" (unix) or ".\" "..\" in dos.public static Listing listAllFiles(java.lang.String searchdir, java.lang.String searchFilter, boolean recurseDirs)
The searchFilter can be any unix style (or DOS style) search expression when using ls or dir. This can also be a file, directory or null. If its a file then this class can be used to determine whether the file exists or not (i.e. if fileFound() == 0 or exists() == false then the file does not exist. If searchFilter is a directory then the directory is listed (if it exists) and if it is set to null then the search is based on the first argument (i.e. the searchdir). This is useful for just lsiting the contents of the directory.
The searchdir can contain "./" or "../" (unix) or ".\" "..\" in dos.public static java.lang.String absolutePath(java.lang.String path)
public static Listing listDir(java.lang.String dir, boolean recurse)
public static java.lang.String[] listDir(java.lang.String dir)
public static Listing listDir(java.net.URL dir, boolean recurse)
public static java.io.File[] listEndsWith(java.lang.String baseDir, java.lang.String endsWith)
public static java.io.File[] listEndsWith(java.lang.String baseDir, java.lang.String endsWith, java.lang.String[] excludedir)
public static java.io.File[] listEndsWith(java.lang.String baseDir, java.lang.String[] endsWith, java.lang.String[] excludedir)