public final class Files
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char |
dirSep
The char used to separate files in the native file system.
|
static java.lang.String |
dirSepStr
The String used to separate files in the native file system.
|
Constructor and Description |
---|
Files() |
Modifier and Type | Method and Description |
---|---|
static boolean |
copy(java.io.File infile,
java.io.File outfile)
Copys the contents of one file to another, as bytes.
|
static boolean |
copyDir(java.io.File sourceDir,
java.io.File destinationDir)
Recursively copies the contents of one directory to another.
|
static java.lang.String |
decode(java.lang.String msg)
Decode a file name.
|
static void |
deleteDirectory(java.io.File directory)
Deletes a directory or file and all files and directories within.
|
static java.lang.String |
encode(java.lang.String msg)
Encode a file name for file system compatibility.
|
static java.lang.String |
escapeWindowsPath(java.lang.String path)
Escapes a Windows directory path by removing the first colon so that it can be used as the end part of
another directory path.
|
static java.lang.String |
fid(java.io.File f)
Appends a path into a string in such a way that lexicographic sorting gives the same results as a walk of
the file hierarchy.
|
static java.lang.String |
fid2path(java.lang.String fid)
Converts an fid back to a file path.
|
static java.lang.String |
fuid(java.io.File f)
Appends a path and date into a string in such a way that lexicographic sorting gives the same results as
a walk of the file hierarchy.
|
protected static java.lang.String |
getDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout:
|
static char |
getFileSeparatorCh()
Gets the String used to separate files in the native file system.
|
static java.lang.String |
getFileSeparatorStr()
Gets the char used to separate files in the native file system.
|
static java.lang.String |
getIDFromFilename(java.io.File file)
Gets a record ID from its file name.
|
static java.lang.String |
getIDFromFilename(java.lang.String filename)
Gets a record ID from its file name.
|
static boolean |
move(java.io.File infile,
java.io.File outfile)
Moves a file from one location to another.
|
protected void |
prtln(java.lang.String s)
Output a line of text to standard out, with datestamp, if debug is set to true.
|
protected static void |
prtlnErr(java.lang.String s)
Output a line of text to error out, with datestamp.
|
static java.lang.StringBuffer |
readFile(java.io.File f)
Reads a file into a StringBuffer.
|
static java.lang.StringBuffer |
readFile(java.lang.String filePath)
Reads a file into a StringBuffer.
|
static java.lang.StringBuffer |
readFileFromJarClasspath(java.lang.String filePathInJarClasspath)
Reads a file from a JAR or location in the runtime classpath.
|
static java.lang.StringBuffer |
readFileToEncoding(java.io.File f,
java.lang.String encoding)
Reads a file to a StringBuffer that will be in the given character encoding, for example UTF-8.
|
static java.lang.StringBuffer |
readInputStream(java.io.InputStream is)
Reads an InputStream into a StringBuffer and closes the stream when done.
|
static void |
setDebug(boolean db)
Sets the debug attribute of the object
|
static boolean |
touch(java.io.File file)
Resets the file mod time to the current time.
|
static boolean |
touch(java.lang.String filePath)
Resets the file mod time to the current time.
|
static void |
writeFile(java.lang.StringBuffer content,
java.io.File file)
Writes a file containing the given content using UTF-8 encoding.
|
static void |
writeFile(java.lang.StringBuffer content,
java.lang.String filePath)
Writes a file containing the given content using UTF-8 encoding.
|
static void |
writeFile(java.lang.String content,
java.io.File file)
Writes a file containing the given content using UTF-8 encoding.
|
static void |
writeFile(java.lang.String content,
java.lang.String filePath)
Writes a file containing the given content using UTF-8 encoding.
|
public static char dirSep
public static java.lang.String dirSepStr
public static java.lang.String getFileSeparatorStr()
public static char getFileSeparatorCh()
public static boolean touch(java.lang.String filePath)
filePath
- A path to a file.public static boolean touch(java.io.File file)
file
- A File.public static final java.lang.StringBuffer readFileFromJarClasspath(java.lang.String filePathInJarClasspath)
filePathInJarClasspath
- The path to the file inside the JAR file or classpathpublic static final java.lang.StringBuffer readFile(java.lang.String filePath) throws java.io.IOException
filePath
- The path to the file.java.io.IOException
- If error.public static final java.lang.StringBuffer readFile(java.io.File f) throws java.io.IOException
f
- The file.java.io.IOException
- If error.public static final java.lang.StringBuffer readFileToEncoding(java.io.File f, java.lang.String encoding) throws java.io.IOException
f
- The File to readencoding
- The encoding to write to, or null to use the default system encodingjava.io.IOException
- If errorpublic static final java.lang.StringBuffer readInputStream(java.io.InputStream is) throws java.io.IOException
is
- The InputStream.java.io.IOException
- If error.public static final void writeFile(java.lang.String content, java.io.File file) throws java.io.IOException
content
- The content to write.file
- The file to write to.java.io.IOException
- If errorpublic static final void writeFile(java.lang.String content, java.lang.String filePath) throws java.io.IOException
content
- The content to write.filePath
- The file to write to.java.io.IOException
- If errorpublic static final void writeFile(java.lang.StringBuffer content, java.io.File file) throws java.io.IOException
content
- The content to write.file
- The file to write to.java.io.IOException
- If error.public static final void writeFile(java.lang.StringBuffer content, java.lang.String filePath) throws java.io.IOException
content
- The content to write.filePath
- The file to write to.java.io.IOException
- If error.public static final boolean copyDir(java.io.File sourceDir, java.io.File destinationDir) throws java.lang.Exception
sourceDir
- The directory to copy.destinationDir
- The directory to copy to.java.lang.Exception
- If error.public static final boolean copy(java.io.File infile, java.io.File outfile) throws java.lang.Exception
infile
- The file to copy.outfile
- The destination of the copied file.java.lang.Exception
- If error.public static boolean move(java.io.File infile, java.io.File outfile)
infile
- The file to move.outfile
- A file denoting the new location.public static void deleteDirectory(java.io.File directory) throws java.lang.SecurityException
directory
- The directory to delete.java.lang.Exception
- If error.java.lang.SecurityException
public static java.lang.String escapeWindowsPath(java.lang.String path)
path
- The original path.public static java.lang.String getIDFromFilename(java.io.File file)
file
- The file.public static java.lang.String getIDFromFilename(java.lang.String filename)
filename
- The file.public static java.lang.String fid(java.io.File f)
fid2path(String fid)
.f
- The file whoes path will be encoded.public static java.lang.String fuid(java.io.File f)
f
- The file whoes path will be encoded.public static java.lang.String fid2path(java.lang.String fid)
fid(File f)
.fid
- The fid.public static java.lang.String encode(java.lang.String msg) throws java.lang.Exception
msg
- A String to encode.java.lang.Exception
- If error.public static java.lang.String decode(java.lang.String msg) throws java.lang.Exception
msg
- Message to decodejava.lang.Exception
- If unable to decode.protected static final java.lang.String getDateStamp()
protected static final void prtlnErr(java.lang.String s)
s
- The text that will be output to error out.protected final void prtln(java.lang.String s)
s
- The String that will be output.public static void setDebug(boolean db)
db
- The new debug value