亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為何createNewFile無法創建文件?

public?static?void?main(String[]?args)?{
		File?file=new?File("resources");
		if(!file.exists()){
			file.mkdir();
		System.out.println("ok");}
		System.out.println(file.getAbsolutePath());
		File?file2=new?File(file,"one.dat");
		if(!file2.exists()){
			try{
			file.createNewFile();
			System.out.println("file2?created");
			}
			catch?(IOException?e){
				System.out.println("error");
			}
			System.out.println(file2.getAbsolutePath());}
		System.out.println(file2.exists());
	}
	
	經查硬盤,創建了resources文件夾,但并沒有創建one.dat,并且輸出結果是:
	E:\javaProject\demo\resources
????????file2?created
????????E:\javaProject\demo\resources\one.dat
????????false
????????
????????java的getAbsolutePath可以獲取one.dat的路徑,但是exists卻判斷one.dat不存在(確實也不存在)
????????
????????請問問題出在哪里,我該如何解決?


正在回答

1 回答

file.createNewFile();這里你要寫file2.createNewFile()才對啊

0 回復 有任何疑惑可以回復我~
#1

好鬼過癮 提問者

非常感謝!
2015-09-28 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為何createNewFile無法創建文件?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號