public class FileUtils extends Object
Facilities are provided in the following areas:
Note that a specific charset should be specified whenever possible. Relying on the platform default means that the code is Locale-dependent. Only use the default if the files are known to always use the platform default.
Origin of code: Excalibur, Alexandria, Commons-Utils
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
closeQuietly(InputStream input) |
static void |
closeQuietly(OutputStream output) |
static int |
copy(InputStream input,
OutputStream output) |
static void |
copyInputStreamToFile(InputStream source,
File destination)
|
static long |
copyLarge(InputStream input,
OutputStream output) |
static void |
copyURLToFile(URL source,
File destination,
int connectionTimeout,
int readTimeout)
Copies bytes from the URL
source to a file
destination. |
static void |
copyUrlToFile(URL source,
File destination,
int connectionTimeout,
int readTimeout,
Proxy proxy)
Copies bytes from the URL
source to a file
destination. |
static FileOutputStream |
openOutputStream(File file) |
public static void copyURLToFile(URL source, File destination, int connectionTimeout, int readTimeout) throws IOException
source to a file
destination. The directories up to destination
will be created if they don't already exist. destination
will be overwritten if it already exists.source - the URL to copy bytes from, must not be nulldestination - the non-directory File to write bytes to
(possibly overwriting), must not be nullconnectionTimeout - the number of milliseconds until this method
will timeout if no connection could be established to the sourcereadTimeout - the number of milliseconds until this method will
timeout if no data could be read from the sourceIOException - if source URL cannot be openedIOException - if destination is a directoryIOException - if destination cannot be writtenIOException - if destination needs creating but can't beIOException - if an IO error occurs during copyingpublic static void copyUrlToFile(URL source, File destination, int connectionTimeout, int readTimeout, Proxy proxy) throws IOException
source to a file
destination. The directories up to destination
will be created if they don't already exist. destination
will be overwritten if it already exists.source - the URL to copy bytes from, must not be nulldestination - the non-directory File to write bytes to
(possibly overwriting), must not be nullconnectionTimeout - the number of milliseconds until this method
will timeout if no connection could be established to the sourcereadTimeout - the number of milliseconds until this method will
timeout if no data could be read from the sourceproxy - the proxy to use to open connectionIOException - if source URL cannot be openedIOException - if destination is a directoryIOException - if destination cannot be writtenIOException - if destination needs creating but can't beIOException - if an IO error occurs during copyingpublic static void copyInputStreamToFile(InputStream source, File destination) throws IOException
InputStream source to a file
destination. The directories up to destination
will be created if they don't already exist. destination
will be overwritten if it already exists.source - the InputStream to copy bytes from, must not be nulldestination - the non-directory File to write bytes to
(possibly overwriting), must not be nullIOException - if destination is a directoryIOException - if destination cannot be writtenIOException - if destination needs creating but can't beIOException - if an IO error occurs during copyingpublic static FileOutputStream openOutputStream(File file) throws IOException
IOExceptionpublic static int copy(InputStream input, OutputStream output) throws IOException
IOExceptionpublic static long copyLarge(InputStream input, OutputStream output) throws IOException
IOExceptionpublic static void closeQuietly(OutputStream output)
public static void closeQuietly(InputStream input)
Copyright © 2016–2021. All rights reserved.