|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.kuka.common.FileUtil
public final class FileUtil
Provides utility methods for working on the file system.
| Field Summary | |
|---|---|
static FilenameFilter |
ConfigFilesFilter
File filter for Configuration files (= *.xml and *.kef). |
static FilenameFilter |
XmlFilesFilter
File filter for XML files. |
| Method Summary | |
|---|---|
static boolean |
areBinaryEqual(File file1,
File file2)
Checks whether the two files are binary equal. offset. |
static boolean |
areBinaryEqual(File file1,
File file2,
int offset)
Checks whether the two files are binary equal starting with a given offset. |
static String |
combinePaths(String... paths)
Puts the given path fragments together. |
static void |
copyFile(File source,
File destination)
copy a file from the source to the destination location. |
static void |
copyFile(InputStream in,
File destination)
Copies an input stream to a destination file. |
static void |
copyFile(String source,
String destination)
copy a file from the source to the destination location. |
static void |
copyFileRecursive(File source,
File destination,
IProgressListener listener)
copies a directory with all sub-directories an containing files from the source to the destination location. |
static void |
copyFiles(File source,
File destination)
Copies a source file to a destination. |
static void |
copyFiles(File source,
File destination,
boolean stopOnError)
Copies a directory with all sub-directories and containing files from the source to the destination location. |
static void |
createAndFillFile(File file,
String content)
Creates and fills a file with the specified content, using the default charset. |
static void |
createAndFillFile(File file,
String content,
Charset charset)
Creates and fills a file with the specified content using the given charset. |
static void |
createAndFillFileAndDir(File file,
String content)
Creates and fills a file with the specified content. |
static void |
createAndFillFileAndDir(File file,
URL url)
Creates and fills a file with the specified content. |
static File |
createTempDir()
Creates a new directory in the system's default temporary-file directory. |
static File |
createTemporaryFolder(String prefix,
String suffix,
File directory)
Creates a new temporary folder. |
static File |
createUniqueFile(String prefix,
String suffix,
File directory)
Creates a new file with the given prefix and suffix in the given directory. |
static boolean |
deleteDirectory(File dir)
Deletes all files recursively in the given directory. |
static boolean |
deleteDirectory(File dir,
boolean stopOnError)
Deletes all files recursively in the given directory. |
static void |
deleteDirectoryContent(File directory)
deletes the content of the specified directory. |
static void |
deleteEmptyDirectories(File directory)
Deletes the directory structure of directories without files. |
static List<File> |
findFile(String fileName,
File rootDirectory)
searches for a file within the root directory and all sub-directories. |
static String |
getAbsolutePath(String path)
Gets the absolute path of the given path without filename. |
static List<String> |
getDirectoryNames(File rootDirectory)
Gets a list of all subdirectories of the given root directory. |
static byte[] |
getFileAsByteArray(File file)
Gets a file as byte array. |
static byte[] |
getFileAsByteArray(String filename)
Gets a file as byte array. |
static String |
getFileAsString(URL url)
Gets the complete content of a file as string. |
static String |
getFileExtension(File file)
Gets the extension of the file. |
static String |
getFileName(String path)
Gets the filename of the given path. |
static String |
getFilenameWithoutExtension(File file)
Gets the name of the file without the extension. |
static String |
getPath(String path)
Gets the path of the given path without a filename. |
static byte[] |
getStreamAsByteArray(InputStream in)
Copies the content of the stream into a byte array. |
static String |
getVendorFromManifest(File jarFile)
Gets the vendor string from a jar file. |
static List<String> |
readStringsFromFile(File inputFile)
Reads the lines from a UTF-8 encoded text file into a list of strings, each line into one string. |
static void |
writeFileContent(File file,
byte[] fileContent)
Writes bytes into a file. |
static void |
writeStringsToFile(File file,
List<String> lines)
Writes the given strings one per line into a UTF-8 encoded text file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final FilenameFilter XmlFilesFilter
public static final FilenameFilter ConfigFilesFilter
| Method Detail |
|---|
public static boolean deleteDirectory(File dir)
dir - The directory.
public static boolean deleteDirectory(File dir,
boolean stopOnError)
dir - The directory.stopOnError - stops the deletion process when a file cannot be deleted. Otherwise the file will be marked as to
delete and the process will be continued...
public static void deleteDirectoryContent(File directory)
throws IOException
directory - the directory whose content should be deleted
IOException - if the contents could not be deletedpublic static void deleteEmptyDirectories(File directory)
directory - the directory to delete
public static void copyFile(String source,
String destination)
throws IOException
source - source filedestination - destination file
IOException - source file was not found, destination file cannot be created
public static void copyFile(File source,
File destination)
throws IOException
source - source filedestination - destination file
IOException - source file was not found, destination file cannot be created
public static void copyFile(InputStream in,
File destination)
throws IOException
in - The input stream. Will be closed on return or exception.destination - The destination file
IOException - if the stream or the file could not be accessed
public static void copyFiles(File source,
File destination,
boolean stopOnError)
throws IOException
source - the source locationdestination - the destination locationstopOnError - if true, an exception is thrown if an error occurs, otherwise the recursive file copy continues
IOException - source file was not found, destination file cannot be created
public static void copyFiles(File source,
File destination)
throws IOException
source - The source filedestination - The destination file
IOException - The Exception is thrown if one of the files could not be accessedpublic static String getFileName(String path)
path - A path.
public static String getPath(String path)
path - A path.
public static String getAbsolutePath(String path)
path - A path.
public static void copyFileRecursive(File source,
File destination,
IProgressListener listener)
throws IOException
source - the source locationdestination - the destination locationlistener - installation listener that logs the copy process (optional)
IOException - source file was not found, destination file cannot be created
public static List<File> findFile(String fileName,
File rootDirectory)
fileName - name of the file to searchrootDirectory - directory where the file should be searched
public static File createTempDir()
public static File createTemporaryFolder(String prefix,
String suffix,
File directory)
throws IOException
File.createTempFile(String, String, File).
prefix - The prefix string to be used in generating the file's name; must be at least three characters longsuffix - The suffix string to be used in generating the file's name; may be null, in which case the suffix
".tmp" will be useddirectory - The directory in which the file is to be created, or null if the default temporary-file directory is
to be used
IOException - Error during creation of folder.
public static void writeFileContent(File file,
byte[] fileContent)
throws IOException
file - The file.fileContent - The bytes.
IOException - The Exception is thrown if the file could not be accessed
public static byte[] getFileAsByteArray(File file)
throws IOException
file - The file.
IOException - if an IO error occurs.
public static byte[] getFileAsByteArray(String filename)
throws IOException
filename - The file name.
IOException - if an IO error occurs.
public static byte[] getStreamAsByteArray(InputStream in)
throws IOException
in - the input stream
IOException - if the stream contains too many bytes, or if an I/O error occurs
public static String getFileAsString(URL url)
throws IOException
url - The file URL.
IOException - The Exception is thrown if the file could not be accessed
public static void createAndFillFile(File file,
String content)
throws IOException
file - The file.content - The content.
IOException - The Exception is thrown if the file could not be accessed
public static void createAndFillFile(File file,
String content,
Charset charset)
throws IOException
file - The file.content - The content.charset - The file should be written using this charset.
IOException - The Exception is thrown if the file could not be accessed
public static void createAndFillFileAndDir(File file,
String content)
throws IOException
file - The file.content - The content.
IOException - The Exception is thrown if the file could not be accessed
public static void createAndFillFileAndDir(File file,
URL url)
throws IOException
file - The file.url - The URL the content has to be read from.
IOException - The Exception is thrown if the file could not be accessedpublic static String getVendorFromManifest(File jarFile)
jarFile - The jar file.
public static String combinePaths(String... paths)
paths - The path fragments.
public static List<String> getDirectoryNames(File rootDirectory)
rootDirectory - The root directory.
public static boolean areBinaryEqual(File file1,
File file2)
throws IOException
file1 - First filefile2 - Second file
IOException - The Exception is thrown if the file could not be accessed
public static boolean areBinaryEqual(File file1,
File file2,
int offset)
throws IOException
file1 - First filefile2 - Second fileoffset - Byte offset
IOException - The Exception is thrown if the file could not be accessed
public static List<String> readStringsFromFile(File inputFile)
throws IOException
inputFile - the input text file
IOException - an I/O error occurred
public static void writeStringsToFile(File file,
List<String> lines)
throws IOException
file - the text filelines - the text lines
IOException - an I/O error occurred
public static File createUniqueFile(String prefix,
String suffix,
File directory)
throws IOException
prefix - the file prefixsuffix - the file suffix. May be null.directory - the directory where to create the file
IOException - if an I/O error occurredpublic static String getFileExtension(File file)
file - file to get extension for.
public static String getFilenameWithoutExtension(File file)
file - the file to get the filename for.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||