あなたはこのようにします:
//use getExternalStorageState to determine if there is an sd card
if (Environment.getExternalStorageState() == null) {
directory = new File(Environment.getDataDirectory()
+ "/RobotiumTestLog/");
photoDirectory = new File(Environment.getDataDirectory()
+ "/Robotium-Screenshots/");
/*
* this checks to see if there are any previous test photo files
* if there are any photos, they are deleted for the sake of
* memory
*/
//if the directory exists, delete files in directory
if (photoDirectory.exists()) {
File[] dirFiles = photoDirectory.listFiles();
if (dirFiles.length != 0) {
for (int ii = 0; ii <= dirFiles.length; ii++) {
dirFiles[ii].delete();
}
}
}
// if no directory exists, create new directory
if (!directory.exists()) {
directory.mkdir();
}
// if phone DOES have sd card
} else if (Environment.getExternalStorageState() != null) {
// search for directory on SD card
directory = new File(Environment.getExternalStorageDirectory()
+ "/RobotiumTestLog/");
photoDirectory = new File(
Environment.getExternalStorageDirectory()
+ "/Robotium-Screenshots/");
if (photoDirectory.exists()) {
File[] dirFiles = photoDirectory.listFiles();
if (dirFiles.length > 0) {
for (int ii = 0; ii < dirFiles.length; ii++) {
dirFiles[ii].delete();
}
dirFiles = null;
}
}
// if no directory exists, create new directory to store test
// results
if (!directory.exists()) {
directory.mkdir();
}
}
それはかなり簡単なプロセスです。ここで行ったのは、SDカードがあるかどうかを確認することでした。SDカードがある場合はディレクトリを検索し、ディレクトリがない場合は作成します。ディレクトリがあり、コンテンツが含まれている場合は、それを消去します。あなたはそれをすべてする必要はありません。必要に応じて、を使用できますEnvironment.getExternalStorageDirectory()
。これでSDカードが取得されます。そこからを作成しbufferedWriter
て書き込みます。<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
マニフェストも追加する必要があります。ご不明な点がございましたら、お気軽にお問い合わせください。
これがお役に立てば幸いです。