public class TFile extends Object
| Constructor and Description |
|---|
TFile() |
| Modifier and Type | Method and Description |
|---|---|
static String |
assemblyPath(Object... pathParts)
路径拼装
|
static boolean |
copyFile(File src,
File dest)
复制文件
|
static void |
deleteFile(File file)
删除文件
|
static void |
deleteFile(String filePath)
删除文件
|
static boolean |
fileExists(String fullPath)
判断文件是否存在
|
static String |
getContextPath()
获得应用的工作根目录路径
|
static String |
getFileDirectory(String filePath)
获取文件所在文件夹路径
|
static String |
getFileExtension(String filePath)
获取文件的扩展名
|
static String |
getFileName(String filePath)
获取文件名称,包含扩展名
|
static long |
getFileSize(File file)
获取文件大小
|
static String |
getLineSeparator()
获得系统默认的换行符号
|
static File |
getResourceFile(String resourcePath)
读取在Context的资源文件 完整路径
|
static String |
getSystemPath(String relativePath)
使用相对路径获得系统的完整路径
|
static String |
getTemporaryPath()
获得系统的临时目录路径
|
static byte[] |
loadFile(File file)
读取 File 对象所代表的文件的内容
|
static byte[] |
loadFile(File file,
long beginPos,
long endPos)
读取 File 对象所代表的文件的内容
|
static byte[] |
loadFileFromContextPath(String filePath)
获取应用的工作根目录为根的相对路径
|
static byte[] |
loadFileFromContextPath(String filePath,
long beginPos,
long endPos)
从应用的工作根目录为根的相对路径读取文件内容
|
static byte[] |
loadFileFromSysPath(String filePath)
从系统路径读取文件内容
|
static byte[] |
loadFileFromSysPath(String filePath,
long beginPos,
long endPos)
从系统路径读取文件内容
|
static byte[] |
loadFileLastLines(File file,
int lastLineNum)
读取文件最后几行记录
|
static byte[] |
loadResource(String resourcePath)
读取在Context的资源文件 (完整路径)
|
static boolean |
mkdir(String dirPath)
创建目录
|
static boolean |
moveFile(File src,
File dest)
移动文件
|
static List<File> |
scanFile(File file,
String pattern)
遍历指定文件对象
|
static List<JarEntry> |
scanJar(File file,
String pattern)
遍历指定jar文件对象
|
static boolean |
writeFile(File file,
boolean append,
byte[] contents)
向文件写入内容
|
static boolean |
writeFile(File file,
boolean append,
byte[] contents,
int offset,
int length)
向文件写入内容
|
static boolean |
writeFile(File file,
byte[] contents)
以追加的形式,向文件写入内容
|
static boolean |
writeFile(File file,
byte[] contents,
int offset,
int length)
以追加的形式,向文件写入内容
|
public static boolean fileExists(String fullPath)
fullPath - 文件完整路径public static String assemblyPath(Object... pathParts)
pathParts - 每个由路劲分割符分割的路径字符串public static long getFileSize(File file) throws IOException
file - 文件对象IOException - IO操作异常public static byte[] loadFileFromSysPath(String filePath)
filePath - 文件路径public static byte[] loadFileFromSysPath(String filePath, long beginPos, long endPos)
filePath - 文件路径beginPos - 起始位置endPos - 结束位置public static byte[] loadFileFromContextPath(String filePath, long beginPos, long endPos)
filePath - 文件路径beginPos - 起始位置endPos - 结束位置,如果值小于0则读取全部,如果大于文件的大小,则自动调整为文件的大小public static byte[] loadFileFromContextPath(String filePath)
filePath - 文件路径public static File getResourceFile(String resourcePath)
resourcePath - 路径起始不带"/"public static byte[] loadResource(String resourcePath)
resourcePath - 路径起始不带"/"public static byte[] loadFile(File file)
file - 文件对象public static byte[] loadFile(File file, long beginPos, long endPos)
file - 文件对象beginPos - 起始位置endPos - 结束位置,如果值小于0则读取全部,如果大于文件的大小,则自动调整为文件的大小public static byte[] loadFileLastLines(File file, int lastLineNum) throws IOException
file - 文件对象lastLineNum - 最后几行的行数IOException - IO 异常public static boolean writeFile(File file, boolean append, byte[] contents, int offset, int length) throws IOException
file - 文件对象append - 是否以追加形式写入contents - 文件内容offset - 偏移值(起始位置)length - 写入长度IOException - IO操作异常public static boolean writeFile(File file, boolean append, byte[] contents) throws IOException
file - 文件对象append - 是否以追加形式写入contents - 文件内容IOException - IO操作异常public static boolean writeFile(File file, byte[] contents, int offset, int length) throws IOException
file - 文件路径contents - 文件内容offset - 偏移值(起始位置)length - 写入长度IOException - IO操作异常public static boolean writeFile(File file, byte[] contents) throws IOException
file - 文件路径contents - 文件内容IOException - IO操作异常public static List<File> scanFile(File file, String pattern)
file - 特定的文件或文件目录pattern - 确认匹配的正则表达式public static List<JarEntry> scanJar(File file, String pattern) throws IOException
file - jar文件对象pattern - 确认匹配的正则表达式IOException - IO 异常public static String getSystemPath(String relativePath)
relativePath - 相对路径public static String getContextPath()
public static String getTemporaryPath()
public static String getLineSeparator()
public static String getFileExtension(String filePath)
filePath - 文件的路径或者文件名public static String getFileDirectory(String filePath)
filePath - 文件的路径或者文件名public static String getFileName(String filePath)
filePath - 文件的路径或者文件名public static boolean moveFile(File src, File dest) throws IOException
src - 原文件dest - 目标文件IOException - IO异常public static boolean mkdir(String dirPath)
dirPath - 目录 file 对象public static boolean copyFile(File src, File dest)
src - 源文件dest - 目标文件public static void deleteFile(File file)
file - 文件对象public static void deleteFile(String filePath)
filePath - 文件路径Copyright © 2020 Voovan. All rights reserved.