آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

File Downloder

فائزه روان بخش  11 سال پیش  11 سال پیش
0 0

با سلام 

در برنامه ای که فایل باینری را از سرور دانلود می کنیم قسمتی که کانکشن رو کانکت (connection.connect) می کنیم خطا می دهد و برنامه وارد catch می شود. در صورتی که آدرس url صحیح است و اینترنتم متصل است

0 0
سورستونو تو قرار بدید (11 سال پیش)
0 0
public class FileDownloader { public static void download(String downloadPath, String filePath) { URL url = null; try { url = new URL(downloadPath); HttpURLConnection c if (url != null) { c url.openConnection(); } connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.connect(); FileOutputStream outputStream = null; outputStream = new FileOutputStream(filePath, true); InputStream inputStream = null; inputStream = connection.getInputStream(); byte[] buffer = new byte[8 * 1024]; int len = 0; while ((len = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, len); System.out.println(); } outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } (11 سال پیش)
0 0
دوست عزیز لطفا قسمت مربوط به قوانین انجمن رو مطالعه کنید . (11 سال پیش)
 برای این سوال 4 پاسخ وجود دارد.
پاسخ به سوال 
فائزه روان بخش  11 سال پیش
0 0

public class FileDownloader {

    public static void download(String downloadPath, String filePath) {

        URL url = null;

        try {

            url = new URL(downloadPath);

            HttpURLConnection connection = null;

            if (url != null) {

 

                connection = (HttpURLConnection) url.openConnection();

 

            }

            connection.setRequestMethod("GET");

            connection.setDoOutput(true);

            connection.connect();

 

            FileOutputStream outputStream = null;

            outputStream = new FileOutputStream(filePath, true);

            InputStream inputStream = null;

            inputStream = connection.getInputStream();

            byte[] buffer = new byte[8 * 1024];

            int len = 0;

            while ((len = inputStream.read(buffer)) > 0) {

 

                outputStream.write(buffer, 0, len);

                System.out.println();

            }

            outputStream.close();

 

        }

        catch (IOException e)

        {

           e.printStackTrace();

 

         }

    }

    }

پاسخ به سوال 
فائزه روان بخش  11 سال پیش
0 0

public class FileDownloader {

    public static void download(String downloadPath, String filePath) {

        URL url = null;

        try {

            url = new URL(downloadPath);

            HttpURLConnection connection = null;

            if (url != null) {

 

                connection = (HttpURLConnection) url.openConnection();

 

            }

            connection.setRequestMethod("GET");

            connection.setDoOutput(true);

            connection.connect();

 

            FileOutputStream outputStream = null;

            outputStream = new FileOutputStream(filePath, true);

            InputStream inputStream = null;

            inputStream = connection.getInputStream();

            byte[] buffer = new byte[8 * 1024];

            int len = 0;

            while ((len = inputStream.read(buffer)) > 0) {

 

                outputStream.write(buffer, 0, len);

                System.out.println();

            }

            outputStream.close();

 

        }

        catch (IOException e)

        {

           e.printStackTrace();

         }

    }

    }

0 0
لطفا راهنمای سایت رو بخونید و سورستون رو در قسمت سورس قرار بدید (11 سال پیش)
پاسخ به سوال 
فائزه روان بخش  11 سال پیش
0 0

package com.example.FileDownload;

import android.util.Log;
import android.widget.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;

public class FileDownloader {
    public static void download(String downloadPath, String filePath) {
        URL url = null;
        String m;
        try {
            url = new URL(downloadPath);
            HttpURLConnection connection = null;
            if (!url.equals(null)) {
                connection = (HttpURLConnection) url.openConnection();
            }
            connection.setRequestMethod("GET");
            connection.setDoOutput(true);
            connection.connect();
            FileOutputStream outputStream = new FileOutputStream(filePath, true);             InputStream inputStream = connection.getInputStream();
            byte[] buffer = new byte[8 * 1024];             int len = 0;             while ((len = inputStream.read(buffer)) > 0) {                 outputStream.write(buffer, 0, len);                 System.out.println();             }             outputStream.close();         } catch (IOException e) {             m = e.toString();         }     } }
0 0
فکر می کنم اصلا هاست رو نمی شناسه. (11 سال پیش)
0 0
کسی نمی دونه ممکنه مشکلش از چی باشه؟ (11 سال پیش)
0 0
دوست عزیز شما باید مراحل رو دونه دونه تست کنید و بخشی که مشکل داره رو پیدا کنید، مثلا اول URL رو توی یک Browser بزنید ببینید دیتا رو درست دارید میگیرید یا نه،اگر از دیتابیس استفاده میکنید ممکنه LocalHost یا حتی Username,Password رو درست وارد نکردید، وقتی فهمیدید مشکل از کدوم بخش برنامتون هست سوال رو محدود کنید تا بتونیم بهتون جواب بدیم، سوال فعلی شما میتونه ده ها مشکل داشته باشه که یک شخصی که به سورس دسترسی نداره نمیدونه از کجاست (11 سال پیش)
0 0
مشکل به خاطر خط connection.connect است. خطای unknown host میده درصورتی که آدرسی که می زنم صحیحه و permission اینترنت رو هم نوشتم (11 سال پیش)
0 0
چند بار از این کلاس استفاده میکنید؟ Url رو هر بار چک میکنید؟ یک لاگ بعد از ارسال URL به کلاستون بذارید ببینید چی برمیگردونه بهتون (11 سال پیش)
0 0
اگر از AVD اندروید استفاده میکنید یک بار AVD رو حذف کنید و دوباره بسازیدش، توی ورژن های مختلف AVD هم همچین مشکلی ممکنه پیش بیاد.روی گوشی تست کردید؟ (11 سال پیش)
پاسخ به سوال 
فائزه روان بخش  11 سال پیش
0 0

دیباگش کردم یوآرال مشکلی نداره. فقط در همین مورد از این کلاس استفاده کردم یعنی یک بار.

رو گوشیمم که امتحان می کنم کرش می کنه


پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .