集册 Java实例教程 删除是否存在

删除是否存在

欢马劈雪     最近更新时间:2020-01-02 10:19:05

486
如果存在则删除

import java.nio.file.Files;
/**
 * 时代Java - nowjava.com 提 供 
**/

import java.nio.file.Path;

import java.nio.file.Paths;


public class Main {

  public static void main(String[] args) throws Exception {

    Path sourceFile = Paths.get("C:/home/docs/users.txt");

    Files.deleteIfExists(sourceFile);

  }


}