Java 实例 - 创建文件

Java 教程 · 2019-02-10 23:12:02

以下实例演示了使用 File 类的 File() 构造函数和 file.createNewFile() 方法来创建一个新的文件

Main.java 文件

import java.io.File; import java.io.IOException; public class Main { public static void main(String[] args) { try{ File file = new File("C:/myfile.txt"); if(file.createNewFile()) System.out.println("文件创建成功!"); else System.out.println("出错了,该文件已经存在。"); } catch(IOException ioe) { ioe.printStackTrace(); } } }

以上代码运行输出结果为:

文件创建成功!

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

查看所有标签

Programming Rust

Programming Rust

Jim Blandy / O'Reilly Media / 2016-8-25 / GBP 47.99

This practical book introduces systems programmers to Rust, the new and cutting-edge language that’s still in the experimental/lab stage. You’ll learn how Rust offers the rare and valuable combination......一起来看看 《Programming Rust》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具