Reputation: 296
In my Asynctask class doInBackground(String... aurl) , I use the following code to save the downloaded file. The file is saved in the same name as it is in the web server. But I heard that it is better to use Environment.getExternalStorageDirectory().getPath(). Is it necessary? How do I use it in my code? Can someone show me? Thanks in advance
String fname;
fname = data.proj.substring( data.proj.lastIndexOf('/')+1, data.proj.length() );
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream("/sdcard/"+fname);
The code is working perfectly now, but I doubt it may cause problem sometimes in future
Upvotes: 0
Views: 677
Reputation: 2056
instead of putting /sdcard/ you can put the following code:
String path=Environment.getExternalStorageDirectory()
.toString() + File.separator
and use path instead of /sdcard/
Upvotes: 2