| Modifier and Type | Method and Description |
|---|---|
static void |
cp(File src,
File dst)
Copies the contents of
src to dst. |
static void |
cp(File src,
OutputStream dst)
Copies the contents of the given input
File to the given
OutputStream. |
static void |
cp(InputStream src,
File dst)
Copies the contents of the given
InputStream to the given
output File. |
static boolean |
equal(File f1,
File f2)
Returns whether the given
Files have the same content. |
static String |
getBaseName(File f)
Returns the file name without its path or extension.
|
static String |
getExtension(File f)
Returns the extension of the given file, or the empty
String
if the file has no extension. |
static byte[] |
head(File f)
Reads the first (up to
512) bytes of the given File. |
static byte[] |
head(File f,
int n)
Reads the first (up to
n) bytes of the given File. |
static void |
mkdir(File... paths)
Creates the directories specified by the given paths.
|
static void |
mv(File src,
File dst)
Moves a file from one path to another.
|
static BufferedInputStream |
newInputStream(File f)
Returns an
InputStream to read from the given File. |
static BufferedOutputStream |
newOutputStream(File f,
WriteOption... options)
Returns an
OutputStream to write to the given File. |
static byte[] |
read(File f)
Reads the content of the given
File. |
static void |
rm(File... files)
Deletes the given
Files. |
static byte[] |
tail(File f)
Reads the last (up to
512) bytes of the given File. |
static byte[] |
tail(File f,
int n)
Reads the last (up to
n) bytes of the given File. |
static void |
touch(File... files)
Creates empty files at the specified paths or updates the last
modification time of the files at the specified paths.
|
public static void cp(File src, File dst) throws IOException
src to dst. If dst
doesn't exist, it will be created. If it already exists, it can be
either a directory or a regular file if src is also a regular
file. Named after the Unix command of the same name.src - the source File.dst - the target File.NullPointerException - if one of the arguments is null.IllegalArgumentException - if src is a directory and
dst is a regular file.IOException - if src doesn't exist or if src is
neither a regular file nor a directory or if an I/O error occurs
during the process.SecurityException - if a security manager exists and denies
read access to src or write access to dst.public static void cp(File src, OutputStream dst) throws IOException
File to the given
OutputStream. Named after the Unix command of the same name.src - the file to copy from.dst - the stream to write to.NullPointerException - if one of the arguments is null.IOException - if src does not exist, or if it is a
directory rather than a regular file, or if it can't be opened
for reading, or if an I/O error occurs during the process.SecurityException - if a security manager exists denies read
access to src.public static void cp(InputStream src, File dst) throws IOException
InputStream to the given
output File. Named after the Unix command of the same name.src - the stream to read from.dst - the file to write to.NullPointerException - if one of the arguments is null.IOException - if dst exists but is a directory rather
than a regular file, or if it does not exist but cannot be
created, or if an I/O error occurs during the process.SecurityException - if a security manager exists denies write
access to dst.public static void mkdir(File... paths) throws IOException
paths - the directories to create.NullPointerException - if paths is null, or if
it contains a null reference.IOException - if one of the specified path already exists and
represents a regular file, or if the requested directory can't
be created.SecurityException - if a security manager exists and denies
read/write access to one of the specified paths.public static void mv(File src, File dst) throws IOException
src - the original file.dst - the destination path.NullPointerException - if one of the arguments is null.IllegalArgumentException - if src is a directory and
dst is a regular file.IOException - if src can't be moved to dst.SecurityException - if a security manager exists and denies
read/write access to src/dst.public static void rm(File... files) throws IOException
Files. Directories will be recursively
deleted. Named after the Unix command of the same name.files - the Files to delete.NullPointerException - if files is null or if
it contains a null reference.IOException - if one of the specified Files can't be
deleted.SecurityException - if a security manager exists and denies
read/write access to one of the specified files or its children.public static void touch(File... files) throws IOException
files - the files to touch.IOException - if an I/O error occurs during the process.SecurityException - if a security manager exists and denies
read/write access to one of the specified files.public static byte[] head(File f) throws IOException
512) bytes of the given File.
Named after the Unix command of the same name.f - the file to read.File.NullPointerException - if f is null.IOException - if f does not exist, or if it is a
directory rather than a regular file, or if it can't be read.SecurityException - if a security manager exists and denies
read access to f.public static byte[] head(File f, int n) throws IOException
n) bytes of the given File.
Named after the Unix command of the same name.f - the file to read.n - the maximum number of bytes to read.File.NullPointerException - if f is null.IllegalArgumentException - if n is negative.IOException - if f does not exist, or if it is a
directory rather than a regular file, or if it can't be read.SecurityException - if a security manager exists and denies
read access to f.public static byte[] tail(File f) throws IOException
512) bytes of the given File.
Named after the Unix command of the same name.f - the file to read.File.NullPointerException - if f is null.IOException - if f does not exist, or if it is a
directory rather than a regular file, or if it can't be read.SecurityException - if a security manager exists and denies
read access to f.public static byte[] tail(File f, int n) throws IOException
n) bytes of the given File.
Named after the Unix command of the same name.f - the file to read.n - the maximum number of bytes to read.File.NullPointerException - if f is null.IOException - if f does not exist, or if it is a
directory rather than a regular file, or if it can't be read.SecurityException - if a security manager exists and denies
read access to f.public static boolean equal(File f1, File f2) throws IOException
Files have the same content. Two
regular files are considered equal if they contain the same bytes.
Two directories are considered equal if they both contain the same
items where an item is either a directory or a regular file (items
must have the same name and content in both directories).f1 - the first File.f2 - the second File.Files have the same content.IOException - if the content of the Files can't be read.public static String getBaseName(File f)
f - the file to get the base name.f's extension-free name.NullPointerException - if f is null.public static String getExtension(File f)
String
if the file has no extension. The returned extension does not include
the leading dot.f - the file to get the extension.f's extension.NullPointerException - if f is null.public static BufferedInputStream newInputStream(File f) throws FileNotFoundException
InputStream to read from the given File.f - the file to read from.InputStream to read from the given File.NullPointerException - if f is null.FileNotFoundException - if f doesn't exist, or if it is
a directory rather than a regular file, or if it can't be opened
for reading.SecurityException - if a security manager exists and denies
read access to f.public static BufferedOutputStream newOutputStream(File f, WriteOption... options) throws IOException
OutputStream to write to the given File.f - the file to write to.options - the write options.OutputStream to write to the given File.NullPointerException - if one of the arguments is null.IllegalArgumentException - if incompatible options are given.FileNotFoundException - if f exists but is a directory
rather than a regular file, or if it does not exist but cannot
be created, or if it cannot be opened for any other reason.IOException - if the WriteOption.CREATE option is given
and the specified file already exists.SecurityException - if a security manager exists and denies
write access to f.public static byte[] read(File f) throws IOException
File.f - the file to read.byte[].NullPointerException - if f is null.IOException - if f does not exist, or if it is a
directory rather than a regular file, or if it can't be read.SecurityException - if a security manager exists and denies
read access to f.Copyright © 2012–2015. All rights reserved.