public class FileUtil extends Object
Modifier and Type | Method and Description |
---|---|
static void |
appendToFile(byte[] contents,
String filename)
Append content to a file
|
static void |
appendToFile(String contents,
String filename)
Append content to a file
|
static String |
changeSeparator(String p)
Changes File.separator into a Windows path to Unix path and vice versa.
|
static long |
compFileDate(String fileName1,
String fileName2)
Test if the time a file was last modified is before, after or
equals than the time another file was last modified
|
static void |
copyFile(InputStream in,
String destFile)
Copy a file to another file using a static buffer of DEFAULT_BUFFER_SIZE
|
static void |
copyFile(InputStream in,
String destFile,
int copyBufferSize)
Copy a file to another file using a buffer of maximum size
|
static void |
copyFile(String sourceFile,
String destFile)
Copy a file to another file using a static buffer of DEFAULT_BUFFER_SIZE
|
static void |
copyFile(String sourceFile,
String destFile,
int copyBufferSize)
Copy a file to another file using a buffer of maximum size
|
static String |
createDir(String dirName)
Creates the directory named by a pathname, if it doesn't exists,
including any necessary but nonexistent parent directories.
|
static void |
deleteFile(String fileName)
Delete the file or directory denoted by a pathname.
|
static boolean |
existFile(String fileName)
Test whether the file denoted by a pathname exists
|
static String |
getTemporalFileName(String filePath)
Gets a non existing filename in the directory passed as
a parameter.
|
static boolean |
isDirectory(String path)
Check if a directory exists and is a directory.
|
static boolean |
isUpdateFile(String fileName1,
String fileName2)
Test if the second file was the last modified
|
static void |
makeBackupFile(String fileName)
Make a backup copy of a file denoted by a pathname, renaming the
original file into a *.bak file.
|
static void |
moveFile(InputStream in,
String destFile)
Move a file to another file using a static buffer of DEFAULT_BUFFER_SIZE
|
static void |
moveFile(InputStream in,
String destFile,
int moveBufferSize)
Move a file to another file using a buffer of maximum size
|
static void |
moveFile(String sourceFile,
String destFile)
MOve a file to another file using a static buffer of DEFAULT_BUFFER_SIZE
|
static void |
moveFile(String sourceFile,
String destFile,
int moveBufferSize)
MOve a file to another file using a buffer of maximum size
|
static byte[] |
readFile(String filename)
Read a file into a buffer sized the size of the file
|
static byte[] |
readFromInputStream(InputStream is)
Reads a set of bytes from an InputStream and returns the data as a byte
array.
|
static Vector |
readLines(String file)
Read all lines of text in a file.
|
static byte[] |
readResourceFile(String fileName)
Tries to read a file from disk, if it doesn't exist try to read from the
CLASSPATH.
|
static void |
renameFile(String oldFileName,
String newFileName)
Rename a file
|
static void |
replace(String file,
String newfile,
String[] cads,
String[] newcads)
Replace the ocurrences of a list of strings in a File with new strings
|
static void |
replace(String file,
String newfile,
String cad,
String newcad)
Replace the ocurrences of a string in a File with new string
|
static void |
restoreBackupFile(String fileName)
Restore a backup copy of a file denoted by a pathname, renaming the
backup file (*.bak) into a original file.
|
static boolean |
swapFile(String source,
String tmp)
From an existing source file, and an existing temporal file,
copy, in a trunc way, the temporal in place of the source file,
and remove the temporal file
|
static void |
writeLines(Vector lines,
String file,
boolean append)
Write an array of strings to the specified file.
|
public static boolean existFile(String fileName)
fileName
- File pathnamepublic static long compFileDate(String fileName1, String fileName2)
fileName1
- First file pathnamefileName2
- Second file pathnamepublic static boolean isUpdateFile(String fileName1, String fileName2)
fileName1
- First file pathnamefileName2
- Second file pathnamepublic static void renameFile(String oldFileName, String newFileName)
oldFileName
- Old file namenewFileName
- New file namepublic static void deleteFile(String fileName)
fileName
- File pathnamepublic static void replace(String file, String newfile, String cad, String newcad) throws IOException
file
- Source filenewfile
- Destination file. If this parameter is 'null'
the changes are stored in the source file.cad
- String to replacenewcad
- New stringIOException
public static void replace(String file, String newfile, String[] cads, String[] newcads) throws IOException
file
- Source filenewfile
- Destination file. If this parameter is 'null'
the changes are stored in the source file.cads
- String list to replacenewcads
- New string listIOException
public static void makeBackupFile(String fileName)
fileName
- File pathnamepublic static void restoreBackupFile(String fileName)
fileName
- File pathnamepublic static byte[] readFile(String filename) throws FileNotFoundException, IOException
filename
- The file full-pathFileNotFoundException
IOException
public static byte[] readResourceFile(String fileName) throws FileNotFoundException, IOException
fileName
- The file full-path or file name (to search into
CLASSPATH)FileNotFoundException
IOException
public static byte[] readFromInputStream(InputStream is) throws IOException
is
- InputStreamIOException
public static Vector readLines(String file) throws IOException
file
- File pathnameIOException
public static void writeLines(Vector lines, String file, boolean append) throws IOException
lines
- array of strings to writefile
- file pathnameappend
- if true the lines will be written to the end of file,
otherwise they will be written to the begin of file and
the file is truncated.IOException
public static void appendToFile(String contents, String filename) throws FileNotFoundException, IOException
contents
- the contentfilename
- the file full-pathFileNotFoundException
IOException
public static void appendToFile(byte[] contents, String filename) throws FileNotFoundException, IOException
contents
- the contentfilename
- the file full-pathFileNotFoundException
IOException
public static boolean swapFile(String source, String tmp)
source
- the existing source file, where to copy the information
from the existing temporal filetmp
- the existing temporal file from where to copy the data
into the source filepublic static void copyFile(InputStream in, String destFile) throws IOException
in
- Source data streamdestFile
- Destination fileIOException
public static void copyFile(String sourceFile, String destFile) throws IOException
sourceFile
- Source filedestFile
- Destination fileIOException
public static void copyFile(String sourceFile, String destFile, int copyBufferSize) throws IOException
sourceFile
- Source filedestFile
- Destination filecopyBufferSize
- Maximum size of the bufferIOException
public static void copyFile(InputStream in, String destFile, int copyBufferSize) throws IOException
in
- Source data streamdestFile
- Destination filecopyBufferSize
- Maximum size of the bufferIOException
public static void moveFile(String sourceFile, String destFile) throws IOException
sourceFile
- Source filedestFile
- Destination fileIOException
public static void moveFile(InputStream in, String destFile) throws IOException
in
- Source data streamdestFile
- Destination fileIOException
public static void moveFile(String sourceFile, String destFile, int moveBufferSize) throws IOException
sourceFile
- Source filedestFile
- Destination filemoveBufferSize
- Maximum size of the bufferIOException
public static void moveFile(InputStream in, String destFile, int moveBufferSize) throws IOException
in
- Source data streamdestFile
- Destination filemoveBufferSize
- Maximum size of the bufferIOException
public static String createDir(String dirName)
dirName
- Directory pathnamepublic static boolean isDirectory(String path)
path
- the path of the directory to be checked.public static String getTemporalFileName(String filePath)
filePath
- The path where is going to be placed the file.Copyright © 2012-2015 JBoss by Red Hat. All Rights Reserved.