文件工具类

类名: FileUtil

list

/**
* 扫描目录下的文件
*
* @param path 路径
* @return 文件集合
*/
FileUtil.list(String path);

list

/**
* 扫描目录下的文件
*
* @param path 路径
* @param fileNamePattern 文件名 * 号
* @return 文件集合
*/
FileUtil.list(String path, String fileNamePattern);

list

/**
* 扫描目录下的文件
*
* @param path 路径
* @param filter 文件过滤
* @return 文件集合
*/
FileUtil.list(String path, FileFilter filter);

list

/**
* 扫描目录下的文件
*
* @param file 文件
* @return 文件集合
*/
FileUtil.list(File file);

list

/**
* 扫描目录下的文件
*
* @param file 文件
* @param fileNamePattern "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
* @return 文件集合
*/
FileUtil.list(File file, String fileNamePattern);

list

/**
* 扫描目录下的文件
*
* @param file 文件
* @param fileNamePatterns "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
* @return 文件集合
*/
FileUtil.list(File file, String fileNamePatterns);

list

/**
* 扫描目录下的文件
*
* @param file 文件
* @param filter 文件过滤
* @return 文件集合
*/
FileUtil.list(File file, FileFilter filter);

getFilename

/**
* 获取文件后缀名
*
* @param path 文件路径
* @return {String}
*/
FileUtil.getFilename(String path);

getFileExtension

/**
* 获取文件后缀名
*
* @param fullName 文件全名
* @return {String}
*/
FileUtil.getFileExtension(String fullName);

getPathWithoutExtension

/**
* 获取文件名,去除后缀名
*
* @param path 文件
* @return {String}
*/
FileUtil.getPathWithoutExtension(String path);

getTempDirPath

/**
* Returns the path to the system temporary directory.
*
* @return the path to the system temporary directory.
*/
FileUtil.getTempDirPath();

toTempDirPath

/**
* 拼接临时文件目录.
*
* @return 临时文件目录.
*/
FileUtil.toTempDirPath(String subDirFile);

getTempDir

/**
* Returns a {@link File} representing the system temporary directory.
*
* @return the system temporary directory.
*/
FileUtil.getTempDir();

toTempDir

/**
* 拼接临时文件目录.
*
* @return the system temporary directory.
*/
FileUtil.toTempDir(String subDirFile);

readToString

/**
* Reads the contents of a file into a String.
* The file is always closed.
*
* @param file the file to read, must not be {@code null}
* @return the file contents, never {@code null}
*/
FileUtil.readToString(File file);

readToString

/**
* Reads the contents of a file into a String.
* The file is always closed.
*
* @param file the file to read, must not be {@code null}
* @param encoding the encoding to use, {@code null} means platform default
* @return the file contents, never {@code null}
*/
FileUtil.readToString(File file, Charset encoding);

readToByteArray

/**
* Reads the contents of a file into a String.
* The file is always closed.
*
* @param file the file to read, must not be {@code null}
* @return the file contents, never {@code null}
*/
FileUtil.readToByteArray(File file);

writeToFile

/**
* Writes a String to a file creating the file if it does not exist.
*
* @param file the file to write
* @param data the content to write to the file
*/
FileUtil.writeToFile(File file, String data);

writeToFile

/**
* Writes a String to a file creating the file if it does not exist.
*
* @param file the file to write
* @param data the content to write to the file
* @param append if {@code true}, then the String will be added to the
* end of the file rather than overwriting
*/
FileUtil.writeToFile(File file, String data, boolean append);

writeToFile

/**
* Writes a String to a file creating the file if it does not exist.
*
* @param file the file to write
* @param data the content to write to the file
* @param encoding the encoding to use, {@code null} means platform default
*/
FileUtil.writeToFile(File file, String data, Charset encoding);

writeToFile

/**
* Writes a String to a file creating the file if it does not exist.
*
* @param file the file to write
* @param data the content to write to the file
* @param encoding the encoding to use, {@code null} means platform default
* @param append if {@code true}, then the String will be added to the
* end of the file rather than overwriting
*/
FileUtil.writeToFile(File file, String data, Charset encoding, boolean append);

toFile

/**
* 转成file
*
* @param multipartFile MultipartFile
* @param file File
*/
FileUtil.toFile(MultipartFile multipartFile, File file);

toFile

/**
* 转成file
*
* @param in InputStream
* @param file File
*/
FileUtil.toFile(InputStream in, File file);

moveFile

/**
* Moves a file.
* <p>
* When the destination file is on another file system, do a "copy and delete".
*
* @param srcFile the file to be moved
* @param destFile the destination file
* @throws NullPointerException if source or destination is {@code null}
* @throws IOException if source or destination is invalid
* @throws IOException if an IO error occurs moving the file
*/
FileUtil.moveFile(File srcFile, File destFile);

deleteQuietly

/**
* Deletes a file, never throwing an exception. If file is a directory, delete it and all sub-directories.
* <p>
* The difference between File.delete() and this method are:
* <ul>
* <li>A directory to be deleted does not have to be empty.</li>
* <li>No exceptions are thrown when a file or directory cannot be deleted.</li>
* </ul>
*
* @param file file or directory to delete, can be {@code null}
* @return {@code true} if the file or directory was deleted, otherwise
* {@code false}
*/
FileUtil.deleteQuietly(File file);

readLines

/**
* NIO 按行读取文件
*
* @param path 文件路径
* @return 行列表
*/
FileUtil.readLines(String path);

readLines

/**
* NIO 按行读取文件
*
* @param file 文件
* @return 行列表
*/
FileUtil.readLines(File file);

readLines

/**
* NIO 按行读取文件
*
* @param path 文件路径
* @return 行列表
*/
FileUtil.readLines(Path path);

readLines

/**
* NIO 按行读取文件
*
* @param path 文件路径
* @param cs 字符集
* @return 行列表
*/
FileUtil.readLines(String path, Charset cs);

readLines

/**
* NIO 按行读取文件
*
* @param file 文件
* @param cs 字符集
* @return 行列表
*/
FileUtil.readLines(File file, Charset cs);

readLines

/**
* NIO 按行读取文件
*
* @param path 文件路径
* @param cs 字符集
* @return 行列表
*/
FileUtil.readLines(Path path, Charset cs);

微信 vs 公众号

如梦技术

精彩内容每日推荐!!!