Android代码实现新建文件夹,并将文件保存到新建的文件夹中
生活随笔
收集整理的这篇文章主要介绍了
Android代码实现新建文件夹,并将文件保存到新建的文件夹中
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
代码如下
String fileName = "SdcardFile-"+System.currentTimeMillis()+".txt"; File dir = new File("/sdcard/mysdcardtest/"); if(!dir.exists()){dir.mkdir(); } if(dir.exists()&&dir.canWrite()){File newFile = new File(dir.getAbsolutePath()+"/"+fileName);FileOutputStream fos = null;try{newFile.createNewFile();if(newFile.exists()&&newFile.canWrite()){fos = new FileOutputStream(newFile);fos.write(randomNumbersString.getBytes());TextView labelView = (TextView)findViewById(R.id.textView1);labelView.setText(fileName+"文件写入SD卡");}}catch(IOException e){e.printStackTrace();}finally{if(fos!=null){try{fos.flush();fos.close();}catch(Exception e){e.printStackTrace();}}}}}如果有帮到您,打个赏呗
《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读总结
以上是生活随笔为你收集整理的Android代码实现新建文件夹,并将文件保存到新建的文件夹中的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: python爬虫,爬取糗事百科并保存到文
- 下一篇: Android 布局属性 Android