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

Problem In Download File

mehdi  10 سال پیش  10 سال پیش
0 0

سلام دو ستان من میخوام فایل رو دانلود کنم این ارور رو میده

 

 

06-05 01:15:48.316: W/System.err(4281): java.io.FileNotFoundException: /storage/sdcard/XXXPIC/Pic.png: open failed: ENOENT (No such file or directory)

 

 

اینم کد:

public class filedownloader {
    public static void download(String downloadpath , String filepath)
    {
        try {
            URL url  = new URL(downloadpath);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setDoOutput(true);
           connection.connect();
          
           int filesize = connection.getContentLength();
          
            File file = new File (filepath);
            if (file.exists()){
                file.delete();
            }
           
            FileOutputStream  outputStream = new FileOutputStream(filepath);

            InputStream inputstream = connection.getInputStream();
            byte[] buffer = new byte[G.DOWNLOAD_BUFFER_SIZE];
            int len = 0;
            int downloadedsize = 0;
            while ((len = inputstream.read(buffer)) > 0){
                outputStream.write(buffer , 0 , len);
                 downloadedsize += len;
                float downloadpercent = downloadedsize / filesize;
                Log.i("LOG" , "Percent : " + downloadpercent);
            }
            outputStream.close();



        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

 

 

 

public class G extends Application {

    public static final String  DIR_SDCARD           = Environment.getExternalStorageDirectory().getAbsolutePath();
    public static final String  DIR_APP              = DIR_SDCARD + "/XXXPIC";
    public static final int     DOWNLOAD_BUFFER_SIZE = 8 * 1024;
    public static final Handler HANDLER              = new Handler();


    @Override
    public void onCreate() {
        super.onCreate();
   new File(DIR_APP).mkdirs();
    }
}

 

 

 

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
   
        filedownloader.download("http://192.168.1.6:1991/dlfile/Pic4.png" , G.DIR_APP + "/Pic.png" );
        Toast.makeText(MainActivity.this, G.DIR_APP, Toast.LENGTH_LONG).show();
         
    }
}

 

 

 

 

 

 

 

 برای این سوال پاسخی وجود ندارد.

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