2017-06-14 17 views
0

例えば、私は、Androidデバイスにテキスト「ABC」のテキストファイルを作成したいが、私は唯一のCodenameOneを使ってアンドロイドの外部パブリックルートフォルダにファイルを書き込む方法は?

FileSystemStorage.getInstance().getCachesDir() 

が見つかりました:

String filePath=FileSystemStorage.getInstance().getCachesDir()+FileSystemStorage.getInstance().getFileSystemSeparator()+"text.txt"; 
OutputStream out=FileSystemStorage.getInstance().openOutputStream(filePath); 
out.write("abc".getBytes()); 

は、どのように私はAndroidの外部の公共のパスを取得することができますルートフォルダ(例:写真、音楽、など)?

答えて

0
In AndroidManifest.xml, one should have 
    <manifest ...> 
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

     ... 
    </manifest> 
Then in the code 
/* Checks if external storage is available for read and write */ 
public boolean isExternalStorageWritable() { 
    String state = Environment.getExternalStorageState(); 
    if (Environment.MEDIA_MOUNTED.equals(state)) { 
     return true; 
    } 
    return false; 
} 

/* Checks if external storage is available to at least read */ 
public boolean isExternalStorageReadable() { 
    String state = Environment.getExternalStorageState(); 
    if (Environment.MEDIA_MOUNTED.equals(state) || 
     Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { 
     return true; 
    } 
    return false; 
} 

public File getAlbumStorageDir(String albumName) { 
    // Get the directory for the user's public pictures directory. 
    File file = new File(Environment.getExternalStoragePublicDirectory(
      **Environment.DIRECTORY_PICTURES**), albumName); 
    if (!file.mkdirs()) { 
     Log.e(LOG_TAG, "Directory not created"); 
    } 
    return file; 
} 

So, by this way one can code and make use of external directory. Browse the link for more information 

     https://developer.android.com/training/basics/data-storage/files.html gives useful info about external storage option availability 
0

あなたは以下のようなexternalstorageパスを取得することができます:

String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Test"; 
    File dir = new File(dirPath); 
    if (!dir.exists()) 
     dir.mkdirs(); 

ここでは、外部記憶装置 でテストフォルダを作成し、今、あなたは以下のようにあなたのOutputStreamを作成することができます。

OutputStream out=FileSystemStorage.getInstance().openOutputStream(dirPath+"text.txt"); 
out.write("abc".getBytes()); 
関連する問題