public final class FileUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static File |
constructFileByDirectoryAndName(String directory,
String fileName)
Create
File instance. |
static void |
copy(String inputFile,
String outputFile)
Creates a copy of a file.
|
static void |
createDirectories(String outPath)
Creates a directory at the provided path.
|
static PrintWriter |
createPrintWriter(OutputStream output,
String encoding)
Creates
PrintWriter instance. |
static String |
createTempCopy(String file,
String tempFilePrefix,
String tempFilePostfix)
Creates a temporary copy of a file.
|
static String |
createTempDirectory(String tempFilePrefix)
Creates a temporary directory.
|
static File |
createTempFile(String path)
Creates a temporary file at the provided path.
|
static File |
createTempFile(String tempFilePrefix,
String tempFilePostfix)
Creates a temporary file.
|
static boolean |
deleteFile(File file)
Deletes a file and returns whether the operation succeeded.
|
static boolean |
directoryExists(String path)
Checks whether there is a directory at the provided path.
|
static boolean |
fileExists(String path)
Checks whether there is a file at the provided path.
|
static OutputStream |
getBufferedOutputStream(String filename)
Creates
OutputStream instance for filename. |
static OutputStream |
getFileOutputStream(File tempFile)
Creates
FileOutputStream instance. |
static OutputStream |
getFileOutputStream(String path)
Creates
OutputStream instance. |
static String |
getFontsDir()
Gets the default windows font directory.
|
static InputStream |
getInputStreamForFile(File file)
Creates
InputStream instance. |
static InputStream |
getInputStreamForFile(String path)
Creates
InputStream instance. |
static String |
getParentDirectoryUri(File file)
Returns an URI of the parent directory for the resource.
|
static RandomAccessFile |
getRandomAccessFile(File tempFile)
Creates
RandomAccessFile instance. |
static boolean |
isFileNotEmpty(String path)
Checks whether is provided file not empty.
|
static String[] |
listFilesInDirectory(String path,
boolean recursive)
Lists all the files located at the provided directory.
|
static File[] |
listFilesInDirectoryByFilter(String outPath,
FileFilter fileFilter)
Lists all the files located at the provided directory, which are accepted by the provided filter.
|
static String |
parentDirectory(URL url)
Returns an URL of the parent directory for the resource.
|
static boolean |
removeFiles(String[] paths)
Removes all of the passed files.
|
static OutputStream |
wrapWithBufferedOutputStream(OutputStream outputStream)
Wraps provided output stream with buffered one.
|
public static String getFontsDir()
public static boolean fileExists(String path)
path - the path to the file to be checked on existencetrue if such a file exists, otherwise falsepublic static boolean isFileNotEmpty(String path)
path - the path to the file to be checked on emptinesstrue if such file is not empty, false otherwisepublic static boolean directoryExists(String path)
path - the path to the directory to be checked on existencetrue if such a directory exists, otherwise falsepublic static String[] listFilesInDirectory(String path, boolean recursive)
path - path to the directoryrecursive - if true, files from all the subdirectories will be returnedpublic static File[] listFilesInDirectoryByFilter(String outPath, FileFilter fileFilter)
outPath - path to the directoryfileFilter - filter to accept files to be listedpublic static PrintWriter createPrintWriter(OutputStream output, String encoding) throws UnsupportedEncodingException
PrintWriter instance.output - output stream where data will be written.encoding - encoding in which data will be written.PrintWriter instance.UnsupportedEncodingException - in case of unknown encoding.public static OutputStream getBufferedOutputStream(String filename) throws IOException
OutputStream instance for filename.filename - name of the file for which output stream will be created.OutputStream instance.FileNotFoundException - if file not found.IOExceptionpublic static OutputStream wrapWithBufferedOutputStream(OutputStream outputStream)
outputStream - output stream to wrap.BufferedOutputStream instance if provided stream was not buffered before.public static File constructFileByDirectoryAndName(String directory, String fileName)
File instance.directory - the parent pathname string.fileName - The child pathname string.File instance.public static File createTempFile(String path) throws IOException
path - path to the temporary file to be created. If it is a directory, then the temporary file
will be created at this directoryIOException - signals that an I/O exception has occurredpublic static OutputStream getFileOutputStream(File tempFile) throws IOException
FileOutputStream instance.tempFile - filename for which output stream will be created.FileOutputStream instance.IOException - in file reading errors.public static InputStream getInputStreamForFile(String path) throws IOException
InputStream instance.path - filename for which output stream will be created.InputStream instance.IOException - in file reading errors.public static InputStream getInputStreamForFile(File file) throws IOException
InputStream instance.file - filename for which output stream will be created.InputStream instance.IOException - in file reading errors.public static OutputStream getFileOutputStream(String path) throws IOException
OutputStream instance.path - filename for which output stream will be created.OutputStream instance.IOException - in file r/w errors.public static RandomAccessFile getRandomAccessFile(File tempFile) throws FileNotFoundException
RandomAccessFile instance.tempFile - file for which RAF will be created.RandomAccessFile instance.FileNotFoundException - in case file not found.public static void createDirectories(String outPath)
outPath - path to the directory to be createdpublic static String getParentDirectoryUri(File file) throws MalformedURLException
file - for which an URI of the parent will be constructed.MalformedURLException - If a protocol handler for the URL could not be found,
or if some other error occurred while constructing the URL.public static boolean deleteFile(File file)
file - file to be deletedpublic static String parentDirectory(URL url) throws URISyntaxException
url - of resourceURISyntaxException - if this URL is not formatted strictly according
to RFC2396 and cannot be converted to a URI.public static File createTempFile(String tempFilePrefix, String tempFilePostfix) throws IOException
Note, that this method creates temporary file with provided file's prefix and postfix
using File.createTempFile(String, String).
tempFilePrefix - the prefix of the copied file's nametempFilePostfix - the postfix of the copied file's nameIOException - signals that an I/O exception has occurred.public static String createTempCopy(String file, String tempFilePrefix, String tempFilePostfix) throws IOException
Note, that this method creates temporary file with provided file's prefix and postfix
using Files.createTempFile(String, String, FileAttribute[]).
file - the path to the file to be copiedtempFilePrefix - the prefix of the copied file's nametempFilePostfix - the postfix of the copied file's nameIOException - signals that an I/O exception has occurred.public static void copy(String inputFile, String outputFile) throws IOException
inputFile - the path to the file to be copiedoutputFile - the path, to which the passed file should be copiedIOException - signals that an I/O exception has occurred.public static String createTempDirectory(String tempFilePrefix) throws IOException
Note, that this method creates temporary directory with provided directory prefix
using Files.createTempDirectory(String, FileAttribute[]).
tempFilePrefix - the prefix of the temporary directory's nameIOException - signals that an I/O exception has occurred.public static boolean removeFiles(String[] paths)
paths - paths to files, which should be removedtrue if all the files have been successfully removed, false otherwiseCopyright © 1998–2025 Apryse Group NV. All rights reserved.