public class Files extends Object
Constructor and Description |
---|
Files() |
Modifier and Type | Method and Description |
---|---|
static File |
backup(File file,
boolean copy)
Backup the given file to a new file called <file-name>~.
|
static boolean |
copy(File from,
File to)
Copy a file.
|
static File |
getClassFile(Class cls)
Return the class file of the given class, or null if the
class is in a jar.
|
static File |
getFile(String name,
ClassLoader loader)
Check the given string for a matching file.
|
static OutputStream |
getOutputStream(String file,
ClassLoader loader)
Return an output stream to the stream(stdout or stderr) or file named
by the given string.
|
static File |
getPackageFile(File base,
String pkg,
boolean mkdirs)
Return the file for the given package.
|
static File |
getSourceFile(Class cls)
Return the source file for the given class, or null if the
source is not in the CLASSPATH.
|
static Writer |
getWriter(String file,
ClassLoader loader)
Return a writer to the stream(stdout or stderr) or file named by the
given string.
|
static Writer |
getWriter(String file,
ClassLoader loader,
String enc)
Return a writer to the stream(stdout or stderr) or file named by the
given string set to the provided charset encoding.
|
static File |
revert(File backup,
boolean copy)
Revert the given backup file to the original location.
|
public static File backup(File file, boolean copy)
public static File revert(File backup, boolean copy)
public static File getSourceFile(Class cls)
public static File getClassFile(Class cls)
public static File getPackageFile(File base, String pkg, boolean mkdirs)
public static File getFile(String name, ClassLoader loader)
name
- the file path or resource nameloader
- a class loader to use in resource lookup, or null
to use the thread's context loaderpublic static Writer getWriter(String file, ClassLoader loader) throws IOException
IOException
getFile(java.lang.String, java.lang.ClassLoader)
public static Writer getWriter(String file, ClassLoader loader, String enc) throws IOException
IOException
getOutputStream(java.lang.String, java.lang.ClassLoader)
public static OutputStream getOutputStream(String file, ClassLoader loader)
public static boolean copy(File from, File to) throws IOException
from
does not exist.IOException
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.