こんにちは今、私のアプリで私のサーバーにあるファイルを自分の携帯電話にダウンロードしようとしています。私は自分のストレージに書き込もうとしていますが、私のSDカードに書き込もうとしていません! 新しいフォルダを作成する際にエラーが発生しました
私はマニフェストに私のデバイス上で必要な権限を持っている:<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
これは、新しいフォルダを作成するにはDownloaderClassからの私のコードがあります。私は戻り値を取得するダウンロード完了...デバッガでは、それは私がそれを望む場所に保存しているパスを表示していますが、私がそこに見える場合....フォルダが空いているはずのフォルダです。
//File new_Folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "MY DOWNLOADED FILES");
String intStorageDirectory = context.getFilesDir().toString();
File new_Folder = new File(intStorageDirectory, "MY DOWNLOADED FILES");
if (!new_Folder.exists()) {
if (!new_Folder.mkdir()) {
return "ERROR: mkdirs() failed for directory" + new_Folder.getAbsolutePath();
}
} else {
Log.i("Info:", "Folder already exists");
}
/**
* Create an output file to store the file for download
*/
inputoutput_file = new File(new_Folder, "downloaded_files.jpg");
InputStream inputStream = new BufferedInputStream(url.openStream(), 8192);
//this will read the information in 1 KB
byte[] data = new byte[1024];
int total = 0;
int count;
OutputStream outputStream = new FileOutputStream(inputoutput_file);
while ((count = inputStream.read(data))!= -1){
total+=count;
if (file_length>0) {
int progress = total * 100/file_length;
publishProgress(progress);
outputStream.write(data, 0, count);
Log.i("Info:", "Progress: " + Integer.toString(progress));
}
}
inputStream.close();
outputStream.close();
return "Download Complete...";
} catch (MalformedURLException e) {
e.printStackTrace();
return "ERROR MalformedURLException" + e.getMessage();
} catch (IOException e) {
e.printStackTrace();
return "ERROR IOException" + e.getMessage();
}
}
@greenappsありがとう! –