Android 台灣中文網

標題: 在sd卡的資料夾中新增子資料夾 [打印本頁]

作者: onlyhska    時間: 2013-8-28 15:21
標題: 在sd卡的資料夾中新增子資料夾

//取得SD卡,在機子上的路徑
        File root = Environment.getExternalStorageDirectory();

        //取得絕對路徑,建立想要的資料夾
        File tempFilePath = new File(root.getAbsolutePath() + "showhair");
              // 判斷路徑是否存在,不存在則直接建立
        
        if (!tempFilePath.exists()) {
             tempFilePath.mkdirs();  //在SD卡上,建立資料夾



show
→sh_01
→sh_02
→sh_03
→sh_04
→sh_05
→sh_06
→sh_07
→sh_08
→sh_09
→sh_10

需要一個主資料夾 裡面還有10個子資料夾
請問程式上面要怎麼改呢><
作者: whl    時間: 2013-8-28 17:47
用 for 重複 mkdirs 10次啊。
作者: onlyhska    時間: 2013-8-29 12:20
whl 發表於 2013-8-28 17:47
用 for 重複 mkdirs 10次啊。

請問大概要怎麼寫呢@@
我不是很懂><
作者: whl    時間: 2013-8-29 22:04
本帖最後由 whl 於 2013-8-29 22:06 編輯

不會吧,連基本的都不會?

  1. for (i = 0; i++; i < 10){
  2.         //取得絕對路徑,建立想要的資料夾
  3.         File tempFilePath = new File(root.getAbsolutePath() + "showhair/sh_" + i);
  4.               // 判斷路徑是否存在,不存在則直接建立
  5.         
  6.         if (!tempFilePath.exists()) {
  7.              tempFilePath.mkdirs();  //在SD卡上,建立資料夾
  8.         .....
  9. }
複製代碼





歡迎光臨 Android 台灣中文網 (https://apk.tw/) Powered by Discuz! X3.1