package com.example.demo;
import java.io.File;
import java.io.IOException;
public class test {
public static void main(String[]args) throws IOException {
//第一种写法;
String fileName = "news.txt";
String parentPath ="d:\\";
File file = new File(parentPath,fileName);
try{
file.createNewFile();
System.out.println("创建成功");
}catch(Exception e){
e.printStackTrace();
}
//第二种写法
File files = new File("d:\\","news1.txt");
try {
files.createNewFile();
System.out.println("创建成功");
}catch (Exception e){e.printStackTrace();}
//第三种写法
File filess = new File("D:\\news2.txt");
try {
filess.createNewFile();
System.out.println("成功");
}catch (Exception e){
e.printStackTrace();
}
}
}
标签:JAVA,入门,printStackTrace,IO,System,createNewFile,File,txt,out From: https://www.cnblogs.com/ZhuAo/p/16921634.html