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 数据库sqlite的使用