Files.delete

简介: Files.delete

终点线只是一个记号而已,其实并没有什么意义,关键是这一路你是如何走的。——村上春树

java中我们除了用这种方式删除文件:

File file = new File("D:\\file\\projects\\img-comparison-demo\\target\\generated-sources");
if (file.exists()) {
    try {
        boolean delete = file.delete();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

还可以使用Files工具类:

try {
    boolean delete = Files.deleteIfExists(Paths.get("D:\\file\\projects\\img-comparison-demo\\target\\generated-sources"));
} catch (IOException e) {
    e.printStackTrace();
}

Files还提供了很多的api就不一一列举了,大家自行探索吧

相关文章
|
7月前
|
Shell
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
adb: error: cannot create file/directory ‘d:/1.png‘: No such file or directory
129 0
|
7月前
|
Java
cannot open shared object file: No such file or directory
cannot open shared object file: No such file or directory
93 0
ftok info: No such file or directory
ftok info: No such file or directory
233 0
Can‘t read file : End of file found 文件:txn_current、current svn无法正常读取文件
Can‘t read file : End of file found 文件:txn_current、current svn无法正常读取文件
Can‘t read file : End of file found 文件:txn_current、current svn无法正常读取文件
|
Unix Shell Linux
|
SQL Oracle 关系型数据库
Online Data Files move
online data files move,move online,
1702 0