I’ve created this code to save a pdf file in sd card, but I want to change the directory that has the saved files, from /sdcard/, to /sdcard/MYDIR/
try {
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
// getting file length
int lenghtOfFile = conection.getContentLength();
// input stream to read file - with 8k buffer
InputStream input = new BufferedInputStream(url.openStream(), 8192);
// Output stream to write file
OutputStream output = new FileOutputStream("/sdcard/yes.pdf");
To create a directory in Java, use
mkdir()ormkdirs()onFile.To correctly create a directory or file on external storage on Android, do not hard-code
/sdcard, largely because it is the wrong value on most Android devices. UseEnvironment.getExternalStorageDirectory()to access the root of external storage.