خرید بک لینک

با سلام و ادب خدمت دوستان قدیمی و جدید

کدهای بنده برای دانلود فایل :


try {
URL url = new URL(sUrl[0]);
coection = (HttpURLCoection) url.openCoection();
//coection.coect();
Log.i("Pdf_download", "1");

///////////////////////////////////////////////////////////

File file=new File("/sdcard/file_name.extension");
if(file.exists()){
fileLength = (int) file.length();
coection.setRequestProperty("Range", "bytes="+(file.length())+"-");
}else {
fileLength = coection.getContentLength();
}
coection.coect();
///////////////////////////////////////////////

// expect HTTP 200 OK, so we don't mistakenly save error report
// instead of the file
if (coection.getResponseCode() != HttpURLCoection.HTTP_OK) {
retu "Server retued HTTP " + coection.getResponseCode()
+ " " + coection.getResponseMessage();
}

// this will be useful to display download percentage
// might be -1: server did not report the length
//int fileLength = coection.getContentLength();

Log.i("Pdf_download", "2");
// download the file
input = coection.getInputStream();
output = new FileOutputStream("/sdcard/file_name.extension");

byte data[] = new byte[4096];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
// allow canceling with back button
if (isCancelled()) {
input.close();
retu null;
}
total += count;
// publishing the progress....
if (fileLength > 0) // only if total length is known
publishProgress((int) (total * 100 / fileLength));
output.write(data, 0, count);
Log.i("Pdf_download", "3");
}
} catch (Exception e) {
retu e.toString();
} finally {
try {
if (output != null)
output.close();
if (input != null)
input.close();
} catch (IOException ignored) {
}

لاگ خطا :


Server retued HTTP 206 Partial Content

با تشکر از همه عزیزان

- - , .

برچسب: نویسنده: محمد رضا جوادیان تاريخ: پنجشنبه 1 بهمن 1394 ساعت: 1:54

صفحه بندی