public abstract class Files extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static File |
canonicalizeFile(File file) |
static String |
canonicalizePathname(String pathname)
Converts 'pathname' into the canonical OS form.
|
static File |
createTempFile(File parentDir,
String prefix,
String extension)
A slightly stricter version of File.createTempFile() in J2SDK 1.3: it requires
that the caller provide an existing parent directory for the temp file.
|
static String |
getFileExtension(File file)
Invariant: (getFileName (file) + getFileExtension (file)).equals (file.getName ()).
|
static String |
getFileName(File file)
Invariant: (getFileName (file) + getFileExtension (file)).equals (file.getName ()).
|
static File |
newFile(File dir,
File file)
Creates a new File from a parent/child pair.
|
static File |
newFile(File dir,
String file)
Creates a new File from a parent/child pair.
|
static File |
newFile(String dir,
String file)
Creates a new File from a parent/child pair.
|
static File[] |
pathToFiles(String[] path,
boolean canonical)
Converts an array of path segments to an array of Files.
|
static String[] |
readFileList(File atfile)
No duplicate elimination.
|
static boolean |
renameFile(File source,
File target,
boolean overwrite)
Renames 'source' to 'target' [intermediate directories are created if necessary].
|
public static String[] readFileList(File atfile) throws IOException
atfile - IOExceptionpublic static File[] pathToFiles(String[] path, boolean canonical)
canonicalizePathname(java.lang.String)
before they are compared for equality
public static String canonicalizePathname(String pathname)
public static String getFileName(File file)
file - File input file descriptor [must be non-null]IllegalArgumentException - if 'file' is nullpublic static String getFileExtension(File file)
file - File input file descriptor [must be non-null]IllegalArgumentException - if 'file' is nullpublic static File newFile(File dir, File file)
dir - [null is ignored]file - [absolute overrides 'dir'; may not be null]public static File newFile(File dir, String file)
dir - [null is ignored]file - [absolute overrides 'dir'; may not be null]public static File newFile(String dir, String file)
dir - [null is ignored]file - [absolute overrides 'dir'; may not be null]public static boolean renameFile(File source, File target, boolean overwrite)
source - file descriptor [file must exist]target - target file descriptor [an existing target may get deleted
if 'overwrite' is true]overwrite - if 'true', forces an existing target to be deletedIllegalArgumentException - if 'source' is null or file does not existIllegalArgumentException - if 'target' is nullpublic static File createTempFile(File parentDir, String prefix, String extension) throws IOException
MT-safety: if several threads use this API concurrently, the temp files created are guaranteed to get created without any collisions and correspond to files that did not exist before. However, if such a temp file is deleted at a later point, this method may reuse its file name. These MT-safety guarantees do not hold if files are created in the same directory outside of this method.
parentDir - parent dir for the temp file [may not be null and must exist]prefix - prefix pattern for the temp file name [only the first 3
chars are guaranteed to be used]extension - pattern for the temp file name [null is equivalient to
".tmp"; this is always normalized to start with "."; only the first 3
non-"." chars are guaranteed to be used]IOException - if a temp file could not be createdCopyright © 2018. All rights reserved.