public class Test { public static void main(String[] args) throws IOException { File file = new File("E:\\test.txt");//实例化File类对象 boolean i =file.createNewFile();//创建文件,根据给定的路径创建 System.out.println(i); } } |
public class Test { public static void main(String[] args) throws IOException { File f = new File("d:" + File.separator + "test.txt"); // 实例化File类的对象 try { f.createNewFile(); // 创建文件,根据给定的路径创建 } catch (IOException e) { e.printStackTrace(); // 输出异常信息 } } } |
public class Test { public static void main(String[] args) throws IOException { File f = new File("E:" + File.separator + "test.txt");// 实例化File类的对象 if (f.exists()) {// 如果文件存在,则删除 f.delete();// 删除文件 } } } |
public class Test { public static void main(String[] args) throws IOException { File f = new File("E:" + File.separator + "test");// 实例化File类的对象 f.mkdir();//创建文件夹 } } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |