最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

誰(shuí)可以幫忙寫(xiě)一段java判斷文件或者文件夾是否存在的代碼

誰(shuí)可以幫忙寫(xiě)一段java判斷文件或者文件夾是否存在的代碼

慕斯卡0459231 2017-05-19 10:33:01
謝謝~~~~~~
查看完整描述

2 回答

已采納
?
田心楓

TA貢獻(xiàn)1064條經(jīng)驗(yàn) 獲得超383個(gè)贊

package?com.may.ninety;

import?java.io.File;
import?java.io.IOException;

public?class?WeekDemo1?{

????public?static?void?main(String[]?args)?{

????????File?dir?=?new?File("/tmp/test/");
????????WeekDemo1.judeDirExists(dir);

????????File?file?=?new?File("/tmp/test/b.txt");
????????WeekDemo1.judeFileExists(file);


????}

????//?判斷文件是否存在
????public?static?void?judeFileExists(File?file)?{

????????if?(file.exists())?{
????????????System.out.println("file?exists");
????????}?else?{
????????????System.out.println("file?not?exists,?create?it?...");
????????????try?{
????????????????file.createNewFile();
????????????}?catch?(IOException?e)?{
????????????????e.printStackTrace();
????????????}
????????}

????}

????//?判斷文件夾是否存在
????public?static?void?judeDirExists(File?file)?{

????????if?(file.exists())?{
????????????if?(file.isDirectory())?{
????????????????System.out.println("dir?exists");
????????????}?else?{
????????????????System.out.println("the?same?name?file?exists,?can?not?create?dir");
????????????}
????????}?else?{
????????????System.out.println("dir?not?exists,?create?it?...");
????????????file.mkdir();
????????}

????}

}


查看完整回答
5 反對(duì) 回復(fù) 2017-05-19
?
yanrun

TA貢獻(xiàn)317條經(jīng)驗(yàn) 獲得超240個(gè)贊

public?static?void?main(String[]?args)?{
		System.out.println(isFileExists("D:/repo"));
	}
	
	private?static?boolean?isFileExists(String?path)?{
		File?file?=?new?File(path);
		return?file.exists();
	}


查看完整回答
反對(duì) 回復(fù) 2017-05-19
  • 2 回答
  • 0 關(guān)注
  • 1919 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)