The Android program reads assets all files (traversing each folder) into the SDcard method _android

Source: Internet
Author: User

The examples in this article describe the way in which the Android programming read assets All files (traversing each folder) into the SDcard. Share to everyone for your reference, specific as follows:

private void Copyassets (String assetdir, string dir) {string[] files;
    try {//Get assets altogether how many files = This.getresources (). Getassets (). List (Assetdir);
    catch (IOException E1) {return;
    File Mworkingpath = new file (dir);
      If the file path does not exist if (!mworkingpath.exists ()) {//Create folder if (!mworkingpath.mkdirs ()) {//folder creation is unsuccessful when called for (int i = 0; i < files.length; i++) {try {//Get the name of each file String FileName = fi
        Les[i]; Whether the folder or file if (!filename.contains (".") is judged by the path
          {if (0 = assetdir.length ()) {copyassets (filename, dir + filename + "/");
          else {copyassets (Assetdir + "/" + filename, dir + "/" + filename + "/");
        } continue;
        File outfile = new file (Mworkingpath, fileName);
        if (outfile.exists ()) Outfile.delete ();
        InputStream in = null; if (0!= aSsetdir.length ()) in = Getassets (). Open (Assetdir + "/" + fileName);
        else in = Getassets (). open (FileName);
        OutputStream out = new FileOutputStream (outfile);
        Transfer bytes from to out byte[] buf = new byte[1024];
        int Len;
        while (len = In.read (buf)) > 0) {out.write (buf, 0, Len);
        } in.close ();
      Out.close ();
      catch (FileNotFoundException e) {e.printstacktrace ();
      catch (IOException e) {e.printstacktrace ();

 }
    }
}

For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Database Operating skills summary" and "Android Control usage Summary"

I hope this article will help you with the Android program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.