嗨朋友!, 我只是试图从url下载图像到内部存储http://github.com/google/fonts/blob/master/apache/roboto/Roboto-Regular.ttf?raw=true。我创建了目录。在Android下载url文件到内部存储时出错?
try
{
File folder = new File(getFilesDir() + "/"+"SS");
if (!folder.exists())
{
folder.mkdir();
Log.i("Directory","Created");
}
//URL connection
URL url = new URL(fonturl);
HttpURLConnection c = (HttpURLConnection)
url.openConnection();
c.connect();
File apkStorage=new File(getFilesDir().getPath());
Log.i("ApkStorage",""+apkStorage);
outputFile=new File(apkStorage.getAbsolutePath() +"/");
if(!outputFile.exists())
{
try {
outputFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Log.e("FIle", "File Created");
}
FileOutputStream fos = new FileOutputStream(outputFile);
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());
}
}
它只是创建文件名我指定download.jpg不从url下载文件到内部存储。
错误:没有在我的目录下载字体显示像这样的错误下载错误异常/data/user/0/sdk.nfnlabs.in.customfonts/files(是一个目录)。它应该直接下载到我的目录,如roboto.tff而不提供文件名。
是什么错误可以用您的问题每股 –
请分享错误日志 – Gaurav
请帮我在哪里出错了 – saiRam89