public class FileTools extends Object
┌─┐ ┌─┐
┌──┘ ┴───────┘ ┴──┐
│ │
│ ─── │
│ ─┬┘ └┬─ │
│ │
│ ─┴─ │
│ │
└───┐ ┌───┘
│ │
│ │
│ │
│ └──────────────┐
│ │
│ ├─┐
│ author:lelouch ┌─┘
│ │
└─┐ ┐ ┌───────┬──┐ ┌──┘
│ ─┤ ─┤ │ ─┤ ─┤
└──┴──┘ └──┴──┘
神兽保佑
代码无BUG!
| 构造器和说明 |
|---|
FileTools() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
appendMethodB(String fileName,
String content)
B方法追加文件:使用FileWriter
|
static void |
copy(File from,
File to)
Just copy a file
|
static void |
copyFileUsingFileChannels(File source,
File dest)
复制文件 (Channels)
|
static void |
copyFileUsingFileStreams(File source,
File dest)
复制文件 (文件流方式)
|
static void |
delete(File file)
删除文件/目录
|
static byte[] |
getBytes(File file)
获取 byte[]
|
static String |
getContentType(File file)
获取 contentType
|
static String |
getContentType(URI uri)
获取 contentType
|
static String |
getFileformat(File file)
后缀名/格式 带点
|
static String |
getFileformatNP(File file)
后缀名/格式 不带点
|
static List<String> |
getFileLine(File file)
获取文件每行
|
static List<String> |
getFileLine(File file,
String charsetName)
获取文件每行
|
static List<String> |
getFileLine(String fileName)
获取文件每行
|
static List<String> |
getFileLine(String fileName,
String charsetName)
获取文件每行
|
static String |
getFileName(File file)
文件名 不带后缀名
|
static long |
getFileSize(byte[] data)
获取文件大小
|
static String |
getFileSize(double B)
文件大小转换
|
static long |
getFileSize(File file)
获取文件大小
|
static long |
getFileSize(InputStream inputStream)
获取文件大小
|
static InputStream |
getInputStream(File file)
获取 InputStream
|
static String |
getJarFileContent(Class cla,
String fileName)
获取jar内文件内容
|
static String |
getkey(String path)
获取文件中的密钥
|
static void |
inputstreamtofile(InputStream ins,
File file)
Inputstreamtofile.
|
static boolean |
isSameFile(File a,
File b)
Indicate if two file refers to the same one
|
static boolean |
stringToFile(String res,
String filePath)
将字符串写入指定文件(当指定的父路径中文件夹不存在时,会最大限度去创建,以保证保存成功!)
|
static String |
txtToString(File file)
读取txt文件的内容
|
static void |
writeFile(File file,
byte[] bs)
写入文件
|
static void |
writeFile(File file,
InputStream is)
写入文件
|
static void |
writeFile(File file,
String content)
写入文件
|
public static String getFileformat(File file)
file - the filepublic static String getFileformatNP(File file)
file - the filepublic static String getFileSize(double B)
B - 字节public static String txtToString(File file)
file - 想要读取的文件对象public static boolean stringToFile(String res, String filePath)
res - 原字符串filePath - 文件路径public static void copyFileUsingFileStreams(File source, File dest) throws IOException
source - the sourcedest - the destIOException - the io exceptionpublic static void copyFileUsingFileChannels(File source, File dest) throws IOException
source - the sourcedest - the destIOException - the io exceptionpublic static void delete(File file)
file - the filepublic static void appendMethodB(String fileName, String content)
fileName - the file namecontent - the contentpublic static void writeFile(File file, String content)
file - the filecontent - the contentpublic static void writeFile(File file, byte[] bs)
file - the filebs - the bspublic static void writeFile(File file, InputStream is) throws IOException
file - the fileis - the isIOException - the io exceptionpublic static List<String> getFileLine(String fileName)
fileName - the file namepublic static List<String> getFileLine(File file)
file - the filepublic static List<String> getFileLine(String fileName, String charsetName)
fileName - the file namecharsetName - the charset namepublic static List<String> getFileLine(File file, String charsetName)
file - the filecharsetName - the charset namepublic static void inputstreamtofile(InputStream ins, File file)
ins - the insfile - the filepublic static String getJarFileContent(Class cla, String fileName)
cla - the clafileName - the file namepublic static String getContentType(URI uri)
uri - the uripublic static String getContentType(File file)
file - the filepublic static long getFileSize(File file)
file - the filepublic static long getFileSize(InputStream inputStream)
inputStream - the input streampublic static long getFileSize(byte[] data)
data - the datapublic static InputStream getInputStream(File file)
file - public static byte[] getBytes(File file)
file - public static void copy(File from, File to)
from - source of the fileto - destination fileCopyright © 2020. All rights reserved.