public class Files extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
Files.LsMode
each 函数的参数类型
|
| 构造器和说明 |
|---|
Files() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
appendWrite(File f,
Object obj)
将内容写到一个文件末尾
InputStream - 按二进制方式写入
byte[] - 按二进制方式写入
Reader - 按 UTF-8 方式写入
其他对象被 toString() 后按照 UTF-8 方式写入
|
static File |
checkFile(String path)
从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
|
static void |
cleanAllFolderInSubFolderes(File dir,
String name)
将一个目录下的特殊名称的目录彻底删除,比如 '.svn' 或者 '.cvs'
|
static boolean |
clearDir(File dir)
清除一个目录里所有的内容
|
static boolean |
copy(File src,
File target)
自动决定是 copy 文件还是目录
|
static boolean |
copyDir(File src,
File target)
拷贝一个目录
|
static boolean |
copyFile(File src,
File target)
相当于 copyFile(src,target,-1)
|
static boolean |
copyFile(File src,
File target,
long count)
将一个文件 copy 一部分(或者全部)到另外一个文件。
|
static boolean |
copyFileWithoutException(File src,
File target,
long count) |
static boolean |
copyOnWrite(File f,
Object obj) |
static boolean |
copyOnWrite(String path,
Object obj) |
static File |
createDirIfNoExists(File d)
传入一个目录对象,如果目录不存在,则创建目录
|
static File |
createDirIfNoExists(String path)
试图生成一个目录对象,如果文件不存在则创建它。
|
static File |
createFileIfNoExists(File f)
如果文件对象不存在,则创建它
|
static File |
createFileIfNoExists(String path)
试图生成一个文件对象,如果文件不存在则创建它。
|
static File |
createFileIfNoExists2(String path) |
static boolean |
createNewFile(File f)
创建新文件,如果父目录不存在,也一并创建。
|
static boolean |
deleteDir(File dir)
强行删除一个目录,包括这个目录下所有的子目录和文件
|
static boolean |
deleteFile(File f)
删除一个文件
|
static File[] |
dirs(File dir)
获取一个目录下所有子目录。
|
static boolean |
equals(File f1,
File f2)
判断两个文件内容是否相等
|
static File[] |
files(File dir,
String suffix)
获取一个目录下所有的文件(不递归,仅仅一层)。
|
static ZipEntry[] |
findEntryInZip(ZipFile zip,
String regex)
根据正则式,从压缩文件中获取文件
|
static File |
findFile(String path)
从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
|
static File |
findFile(String path,
ClassLoader klassLoader)
从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
|
static File |
findFile(String path,
ClassLoader klassLoader,
String enc)
从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
|
static File |
findFile(String path,
String enc)
从 CLASSPATH 下或从指定的本机器路径下寻找一个文件
|
static InputStream |
findFileAsStream(String path)
获取输出流
|
static InputStream |
findFileAsStream(String path,
Class<?> klass)
获取输出流
|
static InputStream |
findFileAsStream(String path,
Class<?> klass,
String enc)
获取输出流
|
static InputStream |
findFileAsStream(String path,
String enc)
获取输出流
|
static File |
getFile(File dir,
String path)
在一个目录下,获取一个文件对象
|
static String |
getMajorName(File f)
获取文件主名。
|
static String |
getMajorName(String path)
获取文件主名。
|
static String |
getName(File f) |
static String |
getName(String path) |
static String |
getParent(String path) |
static String |
getSuffix(File f) |
static String |
getSuffix(String path)
获取文件后缀名,包括 '.'
|
static String |
getSuffixName(File f) |
static String |
getSuffixName(String path)
获取文件后缀名,不包括 '.'
|
static boolean |
isDirectory(File f)
文件对象是否是目录,可接受 null
|
static boolean |
isEquals(File f1,
File f2)
精确比较两个文件是否相等
|
static boolean |
isFile(File f)
文件对象是否是文件,可接受 null
|
static File[] |
ls(File d,
Pattern p,
boolean exclude,
Files.LsMode mode)
在一个目录里列出所有的子文件或者目录
|
static File[] |
ls(File d,
String regex,
Files.LsMode mode)
列文件
|
static File[] |
ls(String path,
String regex,
Files.LsMode mode) |
static File[] |
lsAll(File d,
String regex) |
static File[] |
lsAll(String path,
String regex) |
static File[] |
lsDir(File d,
String regex) |
static File[] |
lsDir(String path,
String regex) |
static File[] |
lsFile(File d,
String regex) |
static File[] |
lsFile(String path,
String regex) |
static boolean |
makeDir(File dir)
创建新目录,如果父目录不存在,也一并创建。
|
static boolean |
move(File src,
File target)
将文件移动到新的位置
|
static String |
read(File f)
读取 UTF-8 文件全部内容
|
static String |
read(String path)
读取 UTF-8 文件全部内容
|
static byte[] |
readBytes(File f)
读取文件全部字节,并关闭文件
|
static byte[] |
readBytes(String path)
读取文件全部字节,并关闭文件
|
static void |
readLine(File f,
Callback<String> callback) |
static List<String> |
readLines(File f) |
static int |
readRange(File f,
int pos,
byte[] buf,
int at,
int len) |
static boolean |
rename(File src,
String newName)
将文件改名
|
static String |
renamePath(String path,
String newName)
修改路径
|
static File |
renameSuffix(File f,
String suffix)
将文件后缀改名,从而生成一个新的文件对象。
|
static String |
renameSuffix(String path,
String suffix)
将文件路径后缀改名,从而生成一个新的文件路径。
|
static File[] |
scanDirs(File dir)
递归查找获取一个目录下所有子目录(及子目录的子目录)。
|
static void |
write(File f,
Object obj)
将内容写到一个文件内,内容对象可以是:
InputStream - 按二进制方式写入
byte[] - 按二进制方式写入
Reader - 按 UTF-8 方式写入
其他对象被 toString() 后按照 UTF-8 方式写入
|
static void |
write(String path,
Object obj)
将内容写到一个文件内,内容对象可以是:
InputStream - 按二进制方式写入
byte[] - 按二进制方式写入
Reader - 按 UTF-8 方式写入
其他对象被 toString() 后按照 UTF-8 方式写入
|
static int |
writeRange(File f,
int pos,
byte[] buf,
int at,
int len) |
public static byte[] readBytes(String path)
path - 文件路径public static byte[] readBytes(File f)
f - 文件public static void write(String path, Object obj)
path - 文件路径,如果不存在,则创建obj - 内容对象public static void write(File f, Object obj)
f - 文件obj - 内容public static void appendWrite(File f, Object obj)
f - 文件obj - 内容public static File renameSuffix(File f, String suffix)
f - 文件suffix - 新后缀, 比如 ".gif" 或者 ".jpg"public static String renameSuffix(String path, String suffix)
path - 文件路径suffix - 新后缀, 比如 ".gif" 或者 ".jpg"public static String getMajorName(String path)
path - 文件路径public static String getSuffixName(File f)
getSuffixName(String)public static String getSuffixName(String path)
path - 文件路径public static String getSuffix(File f)
getSuffix(String)public static String getSuffix(String path)
path - 文件路径public static ZipEntry[] findEntryInZip(ZipFile zip, String regex)
zip - 压缩文件regex - 正则式,用来匹配文件名public static File createFileIfNoExists(String path) throws IOException
path - 文件路径,可以以 ~ 开头,也可以是 CLASSPATH 下面的路径IOException - 创建失败public static File createFileIfNoExists(File f)
f - 文件对象public static File createDirIfNoExists(String path)
path - 文件路径,可以以 ~ 开头,也可以是 CLASSPATH 下面的路径public static File createDirIfNoExists(File d)
d - 文件目录对象public static File findFile(String path, ClassLoader klassLoader, String enc)
path - 文件路径klassLoader - 参考 ClassLoaderenc - 文件路径编码public static File findFile(String path, String enc)
path - 文件路径enc - 文件路径编码public static File findFile(String path, ClassLoader klassLoader)
path - 文件路径klassLoader - 使用该 ClassLoader进行查找public static File[] ls(File d, Pattern p, boolean exclude, Files.LsMode mode)
d - 目录p - 正则表达式对象,如果为空,则是全部正则表达式exclude - true 正则表达式匹配的文件会被忽略,false 正则表达式匹配的文件会被包含mode - 请参看 LsMode 枚举类说明, null 表示 LsMode.ALLFiles.LsModepublic static File[] ls(File d, String regex, Files.LsMode mode)
d - 目录对象regex - 正则表达式mode - 模式ls(File, Pattern, boolean, LsMode)public static File[] ls(String path, String regex, Files.LsMode mode)
ls(File, String, LsMode)public static File[] lsFile(File d, String regex)
ls(File, String, LsMode)public static File[] lsDir(File d, String regex)
ls(File, String, LsMode)public static File[] lsAll(File d, String regex)
ls(File, String, LsMode)public static File findFile(String path)
path - 文件路径public static File checkFile(String path)
path - 文件路径public static InputStream findFileAsStream(String path, Class<?> klass, String enc)
path - 文件路径klass - 参考的类, -- 会用这个类的 ClassLoaderenc - 文件路径编码public static InputStream findFileAsStream(String path, String enc)
path - 文件路径enc - 文件路径编码public static InputStream findFileAsStream(String path, Class<?> klass)
path - 文件路径klass - 参考的类, -- 会用这个类的 ClassLoaderpublic static InputStream findFileAsStream(String path)
path - 文件路径public static boolean isDirectory(File f)
public static boolean isFile(File f)
public static boolean createNewFile(File f) throws IOException
f - 文件对象IOExceptionpublic static boolean makeDir(File dir)
dir - 目录对象IOExceptionpublic static boolean deleteDir(File dir)
dir - 目录public static boolean deleteFile(File f)
f - 文件IOExceptionpublic static boolean clearDir(File dir)
dir - 目录public static boolean copyFile(File src, File target) throws IOException
IOExceptioncopyFile(File, File, long)public static boolean copyFile(File src, File target, long count) throws IOException
src - 源文件target - 目标文件count - 要 copy 的字节数,0 表示什么都不 copy, -1 表示 copy 全部数据IOExceptionpublic static boolean copyFileWithoutException(File src, File target, long count)
public static boolean copy(File src, File target)
src - 源target - 目标public static boolean copyDir(File src, File target) throws IOException
src - 原始目录target - 新目录IOExceptionpublic static boolean move(File src, File target) throws IOException
src - 原始文件target - 新文件IOExceptionpublic static boolean rename(File src, String newName)
src - 文件newName - 新名称public static String renamePath(String path, String newName)
path - 路径newName - 新名称public static void cleanAllFolderInSubFolderes(File dir, String name) throws IOException
dir - 目录name - 要清除的目录名IOExceptionpublic static boolean isEquals(File f1, File f2)
f1 - 文件1f2 - 文件2public static File getFile(File dir, String path)
dir - 目录path - 文件相对路径public static File[] scanDirs(File dir)
dir - 目录public static File[] files(File dir, String suffix)
dir - 目录suffix - 文件后缀名。如果为 null,则获取全部文件public static boolean equals(File f1, File f2)
f1 - 文件对象f2 - 文件对象public static int readRange(File f, int pos, byte[] buf, int at, int len)
public static int writeRange(File f, int pos, byte[] buf, int at, int len)
Copyright © 2017. All rights reserved.