我只是想從URL http://github.com/google/fonts/blob/master/apache/roboto/Roboto-Regular.ttf?raw=true文件在這裏下載到我的系統是我的代碼下載文件「java.io.FileNotFoundException:/用戶/文件(沒有這樣的文件或目錄)」
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;
}
}
文件沒有下載,但拋出錯誤下載錯誤異常/用戶/文檔(沒有這樣的文件或目錄)
'串根= Environment.getExternalStorageDirectory()的toString(); File myDir = new File(root +「/ saved_images」); '使用這個路徑而不是'/ Users/Documents'。 –