从资产到内部应用程序的文件

从资产到内部应用程序的文件

本文介绍了复制其内容的整个文件夹,从资产到内部应用程序的文件/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请,给我建议从资产复制文件夹/数据/数据​​/ my_app_pkg /文件的最好方法。

Please, suggest me the best way of copying a folder from assets to /data/data/my_app_pkg/files.

从资产(WWW)的文件夹中包含的文件和子文件夹。我想完全复制到文件/我的内部应用程序路径提及。

The folder from assets (www) contains files and subfolders. which I want to completely copy to the files/ of my internal app path mentioned.

我能够成功从资产文件复制到内部应用程序的文件/路径,但不能做同样在复制文件夹的情况下,即使assetmanager.list不帮助我,因为它仅复制文件,但不是目录/子文件夹。

I am successfully able to copy a file from assets to internal app files/ path, but unable to do the same in case of copying folder, even assetmanager.list isn't helping me out, as it is copying only the files, but not the directories / subfolders.

敬请建议我更好的方式做我想做什么

Please kindly suggest me the better way to do what I want

推荐答案

希望使用全给你低于code: -

Hope use full to you below code:-

Copy从SD卡的文件夹放到SD卡的另一个文件夹中的文件

资产

            AssetManager am = con.getAssets("folder/file_name.xml");


 public static void copyDirectoryOneLocationToAnotherLocation(File sourceLocation, File targetLocation)
    throws IOException {

if (sourceLocation.isDirectory()) {
    if (!targetLocation.exists()) {
        targetLocation.mkdir();
    }

    String[] children = sourceLocation.list();
    for (int i = 0; i < sourceLocation.listFiles().length; i++) {

        copyDirectoryOneLocationToAnotherLocation(new File(sourceLocation, children[i]),
                new File(targetLocation, children[i]));
    }
} else {

    InputStream in = new FileInputStream(sourceLocation);

    OutputStream out = new FileOutputStream(targetLocation);

    // Copy the bits from instream to outstream
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}

}

这篇关于复制其内容的整个文件夹,从资产到内部应用程序的文件/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:51