博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java创建一个新文件_用Java创建一个新的空文件
阅读量:2532 次
发布时间:2019-05-11

本文共 1478 字,大约阅读时间需要 4 分钟。

java创建一个新文件

The task is to create a new empty file in Java.

任务是用Java创建一个新的空文件。

Creating a new empty file

创建一个新的空文件

To create a new empty file in java – we use of "File" class. The is called with the File object which should be initialized with the file name (and path if you want to specify).

在Java中创建一个新的空文件,我们使用“ File”类的 。 用File对象调用 ,该对象应使用文件名(和路径(如果要指定)初始化)。

The returns a Boolean value if file created successfully it returns "true" otherwise it returns "false".

如果文件创建成功,则将返回一个布尔值,它将返回“ true”,否则将返回“ false”。

Package to use: import java.io.*;

要使用的包: import java.io. *;

Syntax:

句法:

//file object creation    File file = new File("D://sample.txt");    //file creation    file.createNewFile();    Output:    true

Java代码创建一个新的空文件 (Java code to create a new empty file)

//Java code to create a new empty fileimport java.io.*;public class Main {
public static void main(String[] args) {
//creating file object File file = new File("sample.txt"); //following syntax can be used to define //path (D://sample.txt) also //File file = new File("D://sample.txt"); //variable to store result //'true' - file created successfully //'false' - file is not created successfully boolean result = false; try {
result = file.createNewFile(); System.out.println(file.getPath() + " created successfully..."); } catch (IOException exp) {
System.out.println("Error while creating file: " + exp); } }}

Output

输出量

sample.txt created successfully...

翻译自:

java创建一个新文件

转载地址:http://qgazd.baihongyu.com/

你可能感兴趣的文章
51Nod1601 完全图的最小生成树计数 Trie Prufer编码
查看>>
Codeforces 1110D. Jongmah 动态规划
查看>>
android驱动在win10系统上安装的心酸历程
查看>>
优雅的程序员
查看>>
oracle之三 自动任务调度
查看>>
Android dex分包方案
查看>>
ThreadLocal为什么要用WeakReference
查看>>
删除本地文件
查看>>
FOC实现概述
查看>>
base64编码的图片字节流存入html页面中的显示
查看>>
这个大学时代的博客不在维护了,请移步到我的新博客
查看>>
GUI学习之二十一——QSlider、QScroll、QDial学习总结
查看>>
nginx反向代理docker registry报”blob upload unknown"解决办法
查看>>
gethostbyname与sockaddr_in的完美组合
查看>>
kibana的query string syntax 笔记
查看>>
旋转变换(一)旋转矩阵
查看>>
thinkphp3.2.3 bug集锦
查看>>
[BZOJ 4010] 菜肴制作
查看>>
C# 创建 读取 更新 XML文件
查看>>
KD树
查看>>