不好意思
我已经尝试了这么多创建目录在数据/数据/pkg/或sdcard/存储/0/Android/数据/pkg/
在芬兰湾的科特林
i tried:
Android -在data/data/pkg/files目录下创建文件夹
https://www.tabnine.com/code/java/methods/android.content.Context/getExternalFilesDir
https://www.tabnine.com/code/java/methods/android.content.Context/getFilesDir
/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
我在清单中有这些权限:
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
你可以这样做:
String fileName = "FILE_NAME";
String filePath = context.getExternalFilesDir("FOLDER_NAME").toString()+"/"+fileName;
FileOutputStream fileOutputStream = new FileOutputStream(filePath);
例子:在内部存储器中保存位图
public static void downloadToInternalStorage(Context context, Bitmap bitmap) throws IOException {
String fileName = "image.jpg";
String filePath = context.getExternalFilesDir("images").toString()+"/"+fileName;
FileOutputStream fileOutputStream = new FileOutputStream(filePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
}
在芬兰湾的科特林
@kotlin.jvm.Throws(IOException::class)
fun downloadToInternalStorage(context: Context?, bitmap: Bitmap) {
val fileName = "image.jpg"
val filePath: String = context.getExternalFilesDir("images").toString().toString() + "/" + fileName
val fileOutputStream = FileOutputStream(filePath)
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream)
fileOutputStream.flush()
fileOutputStream.close()
}