外部ストレージからディレクトリを作成する際に問題があります。私が使用している方法は次のとおりです。
public String createDir(String npath,String ndir,String file)
{
String[] paths = new String[] { npath, npath + ndir };
for (String path : paths) {
File dir = new File(path);
if (!dir.exists()) {
if (!dir.mkdirs()) {
Log.v(TAG, "ERROR: Creation of directory " + path + " on sdcard failed");
return "ERROR: Creation of directory " + path + " on sdcard failed";
} else {
Log.v(TAG, "Created directory " + path + " on sdcard");
}
}
}
if (!(new File(npath + ndir + file)).exists()) {
try {
AssetManager assetManager = getAssets();
InputStream in = assetManager.open(ndir + file);
OutputStream out = new FileOutputStream(npath + ndir + file);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Log.v(TAG, "Copied " + file);
return "Copied " + file;
} catch (IOException e) {
Log.e(TAG, "Was unable to copy " + file + e.toString());
return "Unable to copy " + file + e.toString();
}
}
else
return "Error!";
}
しかし、私はいつも「エラー:SDカードでのディレクトリ " + パス + "の作成に失敗しました」というメッセージが表示されます。言うまでもなく、これはすでに Android デバイスにインストールされています。アプリケーションのディレクトリを探してみましたが、どこにも見つからず、APK のインストール後に自動的にそのフォルダを作成するはずです。これを解決できる人はいますか?