为了账号安全,请及时绑定邮箱和手机立即绑定

麻烦帮忙看一下这段代码,为什么file.createNewFile()可以省略?

麻烦帮忙看一下这段代码,为什么file.createNewFile()可以省略?

白板的微信 2022-04-03 13:09:45
//---SD Card Storage---File sdCard = Environment.getExternalStorageDirectory();File directory = new File (sdCard.getAbsolutePath() +“/MyFiles”);directory.mkdirs();File file = new File(directory, “textfile.txt”);FileOutputStream fOut = new FileOutputStream(file);OutputStreamWriter osw = newOutputStreamWriter(fOut);//---write the string to the file---osw.write(str);osw.flush();osw.close();
查看完整描述

2 回答

?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

sdCard = Environment.getExternalStorageDirectory(); File directory = new File (sdCard.getAbsolutePath() + “/MyFiles”); directory.mkdirs(); File file = new File(dire

查看完整回答
反对 回复 2022-04-07
?
慕后森

TA贡献1802条经验 获得超5个赞

因为那个文件存在

查看完整回答
反对 回复 2022-04-07
  • 2 回答
  • 0 关注
  • 174 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号