Java 实例 - 删除文件

Java 教程 · 2019-02-10 20:27:13

以下实例演示了使用 delete() 方法将文件删除:

Main.java 文件

import java.io.*; public class Main { public static void main(String[] args) { try{ File file = new File("c:\\test.txt"); if(file.delete()){ System.out.println(file.getName() + " 文件已被删除!"); }else{ System.out.println("文件删除失败!"); } }catch(Exception e){ e.printStackTrace(); } } }

以上代码运行输出结果为(需要在 C 盘上先创建 test.txt 文件):

test.txt 文件已被删除!

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

PHP and MySQL for Dynamic Web Sites : Visual QuickPro Guide

PHP and MySQL for Dynamic Web Sites : Visual QuickPro Guide

Larry Ullman / Peachpit Press / 2005 / USD 39.99

It hasn't taken Web developers long to discover that when it comes to creating dynamic, database-driven Web sites, MySQL and PHP provide a winning open source combination. Add this book to the mix, an......一起来看看 《PHP and MySQL for Dynamic Web Sites : Visual QuickPro Guide》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试