java
  • 01
  • 02
  • 03
  • 04
  • 05
  • 06
  • 07
  • 08
  • 09
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
package cn.meowrain.IO; import java.io.File; import java.io.IOException; public class FileCreate { public static void main(String[] args) { FileCreate create = new FileCreate(); create.create01(); create.create02(); create.create03(); } public void create01(){ String filePath = "d:\\test.txt"; File file = new File(filePath); try { file.createNewFile(); System.out.println("文件创建成功"); }catch (IOException e){ e.printStackTrace(); } } public void create02(){ File parent_file = new File("d:\\"); String fileName = "hello.txt"; File file = new File(parent_file,fileName); try { file.createNewFile(); System.out.println("创建成功"); } catch (IOException e){ e.printStackTrace(); } } public void create03(){ String parentPath = "f:\\"; String fileName = "new3.txt"; File file = new File(parentPath,fileName); try{ file.createNewFile(); System.out.println("创建成功"); } catch (IOException e){ e.printStackTrace(); } } }