|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.xiaoleilu.hutool.FileUtil
public class FileUtil
文件工具类
| 嵌套类摘要 | |
|---|---|
static interface |
FileUtil.ReaderHandler<T>
Reader处理接口 |
| 字段摘要 | |
|---|---|
static String |
CLASS_EXT
Class文件扩展名 |
static String |
JAR_FILE_EXT
Jar文件扩展名 |
static String |
JAR_PATH_EXT
在Jar中的路径jar的扩展名形式 |
static String |
PATH_FILE_PRE
当Path为文件形式时, path会加入一个表示文件的前缀 |
| 构造方法摘要 | |
|---|---|
FileUtil()
|
|
| 方法摘要 | ||
|---|---|---|
static
|
appendLines(Collection<T> list,
String path,
String charset)
将列表写入文件,追加模式 |
|
static void |
appendString(String content,
String path,
String charset)
将String写入文件,追加模式 |
|
static void |
cleanDir(String dirPath)
清空一个目录 |
|
static void |
close(Closeable closeable)
关闭 |
|
static void |
copy(File src,
File dest,
boolean isOverride)
复制文件 如果目标文件为目录,则将源文件以相同文件名拷贝到目标目录 |
|
static File |
createTempFile(String prefix,
String suffix,
File dir,
boolean isReCreat)
创建临时文件 创建后的文件名为 prefix[Randon].suffix From com.jodd.io.FileUtil |
|
static boolean |
del(File file)
删除文件或者文件夹 |
|
static boolean |
del(String fullFileOrDirPath)
删除文件或者文件夹 |
|
static boolean |
equals(File file1,
File file2)
检查两个文件是否是同一个文件 |
|
static String |
getAbsolutePath(String path)
获取绝对路径,相对于classes的根目录 如果给定就是绝对路径,则返回原路径,原路径把所有\替换为/ |
|
static String |
getAbsolutePath(String path,
Class<?> baseClass)
获取绝对路径 此方法不会判定给定路径是否有效(文件或目录存在) |
|
static BufferedWriter |
getBufferedWriter(String path,
String charset,
boolean isAppend)
获得一个带缓存的写入对象 |
|
static String |
getExtension(String fileName)
获得文件的扩展名 |
|
static OutputStream |
getOutputStream(String path)
获得一个输出流对象 |
|
static PrintWriter |
getPrintWriter(String path,
String charset,
boolean isAppend)
获得一个打印写入对象,可以有print |
|
static BufferedReader |
getReader(String path,
String charset)
获得一个文件读取器 |
|
static int |
indexOfLastSeparator(String filePath)
获得最后一个文件路径分隔符的位置 |
|
static boolean |
isExist(String path)
文件是否存在 |
|
static boolean |
isModifed(File file,
long lastModifyTime)
判断文件是否被改动 如果文件对象为 null 或者文件不存在,被视为改动 |
|
static List<String> |
listFileNames(String path)
获得指定目录下所有文件 不会扫描子目录 |
|
static
|
load(FileUtil.ReaderHandler<T> readerHandler,
String path,
String charset)
按照给定的readerHandler读取文件中的数据 |
|
static File[] |
ls(String path)
列出目录文件 给定的绝对路径不能是压缩包中的路径 |
|
static File |
mkdir(String dirPath)
创建文件夹,如果存在直接返回此文件夹 |
|
static void |
move(File src,
File dest,
boolean isOverride)
移动文件或者目录 |
|
static byte[] |
readBytes(File file)
读取文件所有数据 文件的长度不能超过Integer.MAX_VALUE |
|
static List<String> |
readLines(String path,
String charset)
从文件中读取每一行数据 |
|
static
|
readLines(String path,
String charset,
T collection)
从文件中读取每一行数据 |
|
static List<String> |
readLines(URL url,
String charset)
从文件中读取每一行数据 |
|
static
|
readLines(URL url,
String charset,
T collection)
从文件中读取每一行数据 |
|
static String |
readString(String path,
String charset)
读取文件内容 |
|
static File |
touch(String fullFilePath)
创建文件,如果这个文件存在,直接返回这个文件 |
|
static void |
writeBytes(byte[] data,
String path)
写数据到文件中 |
|
static void |
writeBytes(File dest,
byte[] data)
写数据到文件中 |
|
static void |
writeBytes(File dest,
byte[] data,
int off,
int len,
boolean append)
写入数据到文件 |
|
static
|
writeLines(Collection<T> list,
String path,
String charset)
将列表写入文件,覆盖模式 |
|
static
|
writeLines(Collection<T> list,
String path,
String charset,
boolean isAppend)
将列表写入文件 |
|
static void |
writeStream(File dest,
InputStream in)
将流的内容写入文件 |
|
static void |
writeStream(String fullFilePath,
InputStream in)
将流的内容写入文件 |
|
static void |
writeString(String content,
String path,
String charset)
将String写入文件,覆盖模式 |
|
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
public static final String CLASS_EXT
public static final String JAR_FILE_EXT
public static final String JAR_PATH_EXT
public static final String PATH_FILE_PRE
| 构造方法详细信息 |
|---|
public FileUtil()
| 方法详细信息 |
|---|
public static File[] ls(String path)
path - 目录绝对路径或者相对路径
public static List<String> listFileNames(String path)
path - 相对ClassPath的目录或者绝对路径目录
IOException
public static File touch(String fullFilePath)
throws IOException
fullFilePath - 文件的全路径,使用POSIX风格
IOException
public static boolean del(String fullFileOrDirPath)
throws IOException
fullFileOrDirPath - 文件或者目录的路径
IOException
public static boolean del(File file)
throws IOException
file - 文件对象
IOExceptionpublic static File mkdir(String dirPath)
dirPath - 文件夹路径,使用POSIX格式,无论哪个平台
public static File createTempFile(String prefix,
String suffix,
File dir,
boolean isReCreat)
throws IOException
prefix - 前缀,至少3个字符suffix - 后缀,如果null则使用默认.tmpdir - 临时文件创建的所在目录isReCreat - 是否重新创建文件(删掉原来的,创建新的)
IOException
public static void copy(File src,
File dest,
boolean isOverride)
throws IOException
src - 源文件dest - 目标文件或目录isOverride - 是否覆盖目标文件
IOException
public static void move(File src,
File dest,
boolean isOverride)
throws IOException
src - 源文件或者目录dest - 目标文件或者目录isOverride - 是否覆盖目标
IOException
public static String getAbsolutePath(String path,
Class<?> baseClass)
path - 相对路径baseClass - 相对路径所相对的类
public static String getAbsolutePath(String path)
path - 相对路径
public static boolean isExist(String path)
path - 文件路径
public static void close(Closeable closeable)
closeable - 被关闭的对象
public static boolean equals(File file1,
File file2)
file1 - 文件1file2 - 文件2
public static BufferedWriter getBufferedWriter(String path,
String charset,
boolean isAppend)
throws IOException
path - 输出路径,绝对路径charset - 字符集isAppend - 是否追加
IOException
public static PrintWriter getPrintWriter(String path,
String charset,
boolean isAppend)
throws IOException
path - 输出路径,绝对路径charset - 字符集isAppend - 是否追加
IOException
public static OutputStream getOutputStream(String path)
throws IOException
path - 输出到的文件路径,绝对路径
IOExceptionpublic static void cleanDir(String dirPath)
dirPath - 需要删除的文件夹路径
public static BufferedReader getReader(String path,
String charset)
throws IOException
path - 绝对路径charset - 字符集
IOException
public static <T extends Collection<String>> T readLines(String path,
String charset,
T collection)
throws IOException
path - 文件路径charset - 字符集collection - 集合
IOException
public static <T extends Collection<String>> T readLines(URL url,
String charset,
T collection)
throws IOException
url - 文件的URLcharset - 字符集collection - 集合
IOException
public static List<String> readLines(URL url,
String charset)
throws IOException
url - 文件的URLcharset - 字符集
IOException
public static List<String> readLines(String path,
String charset)
throws IOException
path - 文件路径charset - 字符集
IOException
public static <T> T load(FileUtil.ReaderHandler<T> readerHandler,
String path,
String charset)
throws IOException
readerHandler - Reader处理类path - 文件的绝对路径charset - 字符集
IOExceptionpublic static String getExtension(String fileName)
fileName - 文件名
public static int indexOfLastSeparator(String filePath)
filePath - 文件路径
public static void writeString(String content,
String path,
String charset)
throws IOException
content - 写入的内容path - 文件路径charset - 字符集
IOException
public static void appendString(String content,
String path,
String charset)
throws IOException
content - 写入的内容path - 文件路径charset - 字符集
IOException
public static String readString(String path,
String charset)
throws IOException
path - 文件路径charset - 字符集
IOException
public static <T> void writeLines(Collection<T> list,
String path,
String charset)
throws IOException
list - 列表path - 绝对路径charset - 字符集
IOException
public static <T> void appendLines(Collection<T> list,
String path,
String charset)
throws IOException
list - 列表path - 绝对路径charset - 字符集
IOException
public static <T> void writeLines(Collection<T> list,
String path,
String charset,
boolean isAppend)
throws IOException
list - 列表path - 绝对路径charset - 字符集isAppend - 是否追加
IOException
public static void writeBytes(byte[] data,
String path)
throws IOException
data - 数据path - 目标文件
IOException
public static void writeBytes(File dest,
byte[] data)
throws IOException
dest - 目标文件data - 数据
IOException
public static void writeBytes(File dest,
byte[] data,
int off,
int len,
boolean append)
throws IOException
dest - 目标文件data - 数据off - len - append -
IOException
public static byte[] readBytes(File file)
throws IOException
file - 文件
IOException
public static void writeStream(File dest,
InputStream in)
throws IOException
dest - 目标文件in - 输入流
IOException
public static void writeStream(String fullFilePath,
InputStream in)
throws IOException
fullFilePath - 文件绝对路径in - 输入流
IOException
public static boolean isModifed(File file,
long lastModifyTime)
file - 文件对象lastModifyTime - 上次的改动时间
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||