I am just trying to download file from url http://github.com/google/fonts/blob/master/apache/roboto/Roboto-Regular.ttf?raw=true to my system here is my code
getDirectory=(Button)findViewById(R.id.btn_newDirectory);
getDirectory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
new DownloadingTask().execute();
}
});
private class DownloadingTask extends AsyncTask<Void,Void,Void>{
@Override
protected Void doInBackground(Void... voids) {
try {
URL url = new URL(fonturl);
HttpURLConnection c = (HttpURLConnection)
url.openConnection();
c.setRequestMethod("GET");
c.connect();
FileOutputStream fos = new FileOutputStream("/Users/Documents");
Log.i("Download","complete");
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
}
catch (Exception e) {
e.printStackTrace();
outputFile = null;
Log.e("Error", "Download Error Exception " + e.getMessage());
}
return null;
}
}
File is not downloaded but throwing error Download Error Exception /Users/Documents (No such file or directory)