code to donload a file and copy it in SDCard,and get file created date...in Android

 ///if SDCard is Existed then,download files categories.xml , Audios.xml , Reviews.xml , Video.xml files in SDCard as follows.
        try {
           
            URL url = new URL("http://9.dharani.org/Upendra/Category.xml");               
            InputStream input = url.openStream();               
        try {
            //place image in SdCard..
            //below two lines are same,but the difference is their API levels..
            //System.out.println("Local Path for sdcard==== "+getExternalFilesDir(null));//API Level-8
            System.out.println("Local Path for sdcard==== "+Environment.getExternalStorageDirectory()+"/Category.xml");//API Level-1                  
           
            OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory()+"/Category.xml");
            try {
                int aReasonableSize = 1000;
                byte[] buffer = new byte[aReasonableSize];
                int bytesRead = 0;
                while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
                    output.write(buffer, 0, bytesRead);//buffer.length);
                }
            } //try
            finally {
                output.close();
            }//finally
        } finally {
            input.close();
        }//finally
        }catch (Exception e) {
            e.printStackTrace();
        }//catch
        ///code to get file last modified dateee
        File fXmlFile = new File("sdcard/Category.xml");
        Date localFileDate = new Date(fXmlFile.lastModified());
         System.out.println("---CategoryFilecreatedDate--"+localFileDate.toString());

Comments

Popular posts from this blog

Custom Dialog with no title and full screen in Android

Best working code to set Date limits on Date Picker Dialog,in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard