在java中通过路径创建文件对象

来源:互联网 发布:详细数据类网游小说 编辑:程序博客网 时间:2024/04/29 09:30

public class MyFile {

 public static void main(String[] args) throws IOException {
  //通过路径创建文件对象
  File file = new File("C:\\test.txt");
  if (!file.exists()) { //如果不存在就创建
   file.createNewFile(); //抛出异常
  }else {
   System.out.println("文件已经存在");
  }

 }

}

0 0
原创粉丝点击