小編給大家分享一下createNewFile()方法有什么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
方法自動(dòng)創(chuàng)建此抽象路徑名的新文件。文件鎖設(shè)備應(yīng)該使用這種方法,文件鎖定會(huì)導(dǎo)致協(xié)議無(wú)法進(jìn)行可靠地工作。
1.聲明
以下是createNewFile()方法的聲明:
public boolean createNewFile()
2.參數(shù)
NA
3.返回值
此方法返回true,如果指定的文件不存在,并已成功創(chuàng)建。如果該文件存在,該方法返回false。
4.異常
IOException -- 如果發(fā)生I/ O錯(cuò)誤
SecurityException --如果SecurityManager.checkWrite(java.lang.String) 方法拒絕寫入權(quán)限的文件
5.例子
下面的示例演示createNewFile()方法的用法。
package com.yiibai;
import java.io.File;
public class FileDemo {
public static void main(String[] args) {
File f = null;
boolean bool = false;
try{
// create new file
f = new File("test.txt");
// tries to create new file in the system
bool = f.createNewFile();
// prints
System.out.println("File created: "+bool);
// deletes file from the system
f.delete();
// delete() is invoked
System.out.println("delete() method is invoked");
// tries to create new file in the system
bool = f.createNewFile();
System.out.println("File created: "+bool);
}catch(Exception e){
e.printStackTrace();
}
}
}
以上是createNewFile()方法有什么用的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!
分享題目:createNewFile()方法有什么用-創(chuàng)新互聯(lián)
鏈接URL:http://chinadenli.net/article44/eojhe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、面包屑導(dǎo)航、做網(wǎng)站、動(dòng)態(tài)網(wǎng)站、網(wǎng)站導(dǎo)航、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容