2017-06-03 138 views

回答

0

//這將創建一個內部目錄; 文件myAppDir = context.getDir(「myAppDir」,Context.MODE_PRIVATE);

//從目錄中獲取文件。 文件myFile =新文件(myAppDir,「myFile」);

0

試試這個

public static final String CAMERA_DIR = "/android/data/YourPackageName/"; 

//創建調用此

CreateDirByName("database"); 

//方法來創建

public static  String CreateDirByName(String subdir){ 
     String path = null; 
     if(!IsSdcardAvailable()){ 
      return null; 
     } 

     try{ 
      File newdir = new File (Environment.getExternalStorageDirectory() + CAMERA_DIR +subdir); 
      if(!newdir.exists()) 
      { 
       newdir.mkdirs(); 
      } 
      path= newdir.getPath(); 
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
      path= null; 
     } 
     return path; 

    } 

//檢查SdCard

public static Boolean IsSdcardAvailable() 
    { 
     boolean mExternalStorageAvailable = false; 
     boolean mExternalStorageWriteable = false; 
     String state = Environment.getExternalStorageState(); 

     if (Environment.MEDIA_MOUNTED.equals(state)) { 
      // We can read and write the media 
      mExternalStorageAvailable = mExternalStorageWriteable = true; 

     } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { 
      // We can only read the media 
      mExternalStorageAvailable = true; 
      mExternalStorageWriteable = false; 
     } 
     else 
     { 
      mExternalStorageAvailable = mExternalStorageWriteable = false; 
     } 
     return(mExternalStorageWriteable); 
    } 
相關問題