[英]How to create a folder in Download directory (Android Studio)
我想在“下載”目錄中創建一個目錄(該目錄存儲我從網絡下載的所有文件),以便將手機插入PC后可以在瀏覽器中看到它。
File myDirectory = new File(dir, "NewDirectory");
dir的值應該是多少?
File dir = new File(Environment.getExternalStorageDirectory() + "/Download/your folder/");
dir.mkdirs(); // creates needed dirs
不要忘記詢問棉花糖或更高版本的權限,並將寫入存儲權限添加到Android Manifest,例如: https : //stackoverflow.com/a/34722591/4479004
嘗試以下代碼
private void createDirectoryAndSaveFile() {
File direct = new File(Environment.getExternalStorageDirectory() + "/Download/DirName");
if (!direct.exists()) {
File wallpaperDirectory = new File("/sdcard/Download/DirName/");
wallpaperDirectory.mkdirs();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.