Answer the question
In order to leave comments, you need to log in
Problem uploading a file?
A very interesting problem has arisen.
We have a directory (for example mnt/sdcard/myapp/mydir).
We load an mp3 file from the Internet into it.
The file is successfully uploaded to the directory and everything is fine.
But when the size of this folder (or the number of files in it - I still don’t understand) becomes too large (> 800 MB) or, accordingly, there are too many files - the files start uploading there every other time, and that’s not all. Recreating this folder (and deleting files from there) helps.
Here is the load function in the service:
My code (references to the UI removed)
private void downloadAudio(final Audio audio)
{
final String audioDirPath=PathPackage.audioDirPath;
final String audioName = audio.title;
final long aid = audio.aid;
File audioFile = new File(audioDirPath+ "/" + audio.title +"["+audio.aid+"]"+".mp3");
Log.i("DownloadManager", "Start download to: " + audioFile.getAbsolutePath());
byte[] buffer = new byte[1024];
URL url = null;
int totalSize=0;
int loaded=0;
try {
url = new URL(audio.url);
} catch (MalformedURLException e1) {
e1.printStackTrace();
return;
}
URLConnection ucon = null;
try {
ucon = url.openConnection();
ucon.setReadTimeout(TIMEOUT_CONNECTION);
ucon.setConnectTimeout(TIMEOUT_SOCKET);
} catch (IOException e1) {
e1.printStackTrace();
Toast.makeText(this, e1.getMessage(), Toast.LENGTH_LONG).show();
return;
}
InputStream is = null;
try {
is = ucon.getInputStream();
} catch (IOException e1) {
e1.printStackTrace();
Toast.makeText(getApplicationContext(), e1.getMessage(), Toast.LENGTH_LONG).show();
return;
}
totalSize = ucon.getContentLength();
BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(audioFile);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
int read = 0;
try {
while ((read = inStream.read(buffer)) != -1)
{
outStream.write(buffer,0,read);
} catch (Exception e)
{
e.printStackTrace();
}
try {
outStream.flush();
outStream.close();
inStream.close();
} catch (Exception e){
e.printStackTrace();
}
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
}
Answer the question
In order to leave comments, you need to log in
It? android.stackexchange.com/questions/12422/is-there-a-maximum-number-of-files-per-directory-or-maximum-directory-size
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question