Я создал приложение для Android, чтобы загрузить изображение и сохранить его во внешнем каталоге, но приложение загружает файл и сохраняет его во внутреннем каталоге. это мой кодКак сохранить загруженные файлы во внешнее хранилище
protected String doInBackground(String... aurl) {
int count;
try {
File root = Environment.getExternalStorageDirectory();
File dir = new File(root.getAbsolutePath() + "/storage/extSdCard/prateek");
if(dir.exists() == false){
dir.mkdirs();
}
URL url = new URL(aurl[0]);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
InputStream input = new BufferedInputStream(url.openStream());
// File SDCardRoot = Environment.getExternalStorageDirectory();
//create a new file, to save the downloaded file
File file = new File(dir,"downloaded_file.png");
OutputStream output = new FileOutputStream(file);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress("" + (int) ((total * 100)/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
}
return null;
}
приведенный выше код дает мне путь как: /storage/emulated/0/prateek/download_file.png " –
PLS проверит журнал и скажет путь к файлу File = new File (dir," loaded_file.png "); file.getAbsolutePath(); –