public final class FileUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static File |
constructFileByDirectoryAndName(String directory,
String fileName) |
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) |
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) |
static FileOutputStream |
getFileOutputStream(File tempFile) |
static OutputStream |
getFileOutputStream(String path) |
static String |
getFontsDir()
Gets the default windows font directory.
|
static InputStream |
getInputStreamForFile(String path) |
static String |
getParentDirectoryUri(File file) |
static RandomAccessFile |
getRandomAccessFile(File tempFile) |
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) |
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
UnsupportedEncodingExceptionpublic static OutputStream getBufferedOutputStream(String filename) throws FileNotFoundException
FileNotFoundExceptionpublic static OutputStream wrapWithBufferedOutputStream(OutputStream outputStream)
public static File constructFileByDirectoryAndName(String directory, String fileName)
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 FileOutputStream getFileOutputStream(File tempFile) throws FileNotFoundException
FileNotFoundExceptionpublic static InputStream getInputStreamForFile(String path) throws IOException
IOExceptionpublic static OutputStream getFileOutputStream(String path) throws IOException
IOExceptionpublic static RandomAccessFile getRandomAccessFile(File tempFile) throws FileNotFoundException
FileNotFoundExceptionpublic static void createDirectories(String outPath)
outPath - path to the directory to be createdpublic static String getParentDirectoryUri(File file) throws MalformedURLException
MalformedURLExceptionpublic 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
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
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
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–2022 iText Group NV. All rights reserved.