繁体   English   中英

将文件资产打包到apk中?

[英]Pack files assets into apk?

我的应用程序在设备上时需要使用一些文件。 现在,我只能通过复制这些文件并通过手动使用计算机将其直接粘贴到设备中来完成此操作。

那么有没有办法将这些文件打包或复制到apk中,并在设备上安装时,程序会将它们粘贴到设备中自动指定文件夹

我想要打包的文件是狮身人面像语音识别的模型

谢谢。

您可以将文件放在项目的/ assets目录中,这将直接将其构建到apk中,然后在运行时使用Context对象上的getAssets()方法访问该文件以复制它或任何您需要的文件:

InputStream input = context.getAssets().open("your_file_name");
String outPath = "/some/path/your_file_name";
OutputStream output = new FileOutputStream(outPath);

// transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
    output.write(buffer, 0, length);
}

// Close the streams
output.flush();
output.close();
input.close();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM