安卓:从assets目录下复制文件到指定目录
有些时候我们直接将某些资源文件内置到apk中,便于直接使用。
1.首先将文件放置在项目/app/src/main/assets目录中
2.功能代码:
public void copyFile(String filename) {
InputStream in = null;
FileOutputStream out = null;
// path为指定目录
String path = this.context.getApplicationContext().getFilesDir().getAbsolutePath() +"/"+filename; // data/data目录
File file = new File(path);
if (!file.exists()) {
try {
in = this.context.getAssets().open(filename); // 从assets目录下复制
out = new FileOutputStream(file);
int length = -1;
byte[] buf = new byte[1024];
while ((length = in.read(buf)) != -1) {
out.write(buf, 0, length);
}
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
}
3.调用方法: coptFile("文件名")
安卓:从assets目录下复制文件到指定目录的更多相关文章
- Android复制Assets目录下的文件到指定目录
package com.android.demo; import java.io.File; import java.io.FileOutputStream; import java.io.Input ...
- winform复制文件到指定目录
执行步骤 弹出选择对话框:var openFileDialog = new OpenFileDialog(); 设置选择内容,如所有图片:openFileDialog.Filter="图像文 ...
- C# 获得目录下所有文件或指定文件类型文件(包含所有子文件夹)
public partial class FileGet { /// <summary> /// 私有变量 /// </summary> private static List ...
- linux 系统如何复制文件到指定目录
首先使用命令函数“cp” 即copy的缩写, 一般模式: cp filename 路径. 如file1在A目录下,我们想把file1复制到B目录下 命令为 cp file1 /home/B ...
- visual studio使用dos命令在生成项目时复制文件到指定目录
本人使用软件:vs2015 拷贝“项目1”的 bin目录 下, 项目配置的名称(“Release”,“Debug”)目录下,所有内容到“项目2”输出目录(存在直接覆盖): xcopy $(Soluti ...
- 【Linux】【三】linux 复制文件到指定目录
将 application/file/test/logs/ 下的文件 logs.log , logs.tar 复制到 application/file/test/tools/ 下,并新建文件夹[l ...
- VS生成时复制文件到指定目录
1.右键项目属性,选择生成事件,再点击"编辑后生成事件",可以直接在编辑框内填写命令行,如图: 2.也可以在弹出的编辑框内,写命令,$(ProjectDir)这种是系统的宏路径,具 ...
- linux拷贝多个目录下的文件到同一个目录
拷贝a目录下的a.txt和b目录下的b.txt到c目录 cp -a \ /root/a/a.txt \ /root/b/b.txt \ /root/c/
- Unix 复制文件至指定目录
cp /gaps/log/20160504/bxdx_20160504.log.Z /home 将/gaps/log/20160504/bxdx_20160504.log.Z 文件复制到home路 ...
随机推荐
- 软件架构,WEB - MVC,MVP,MVVM
参考 https://www.zhihu.com/question/20148405/answer/107071448 http://www.cnblogs.com/indream/p/3602348 ...
- laravel 排除csrf验证
中(*排除所有路由)
- Unity3D~纹理格式
因为之前自己从来没有好好看过这部分,一直都是用的DXT压缩图片,结果发现原来ios是不支持DXT的, 还不知道我项目那么卡是不是这部分引起的, 但愿是~这样应该就可以解决游戏在ios上只有6.8帧的问 ...
- python面试题手动总结答案锦集
数据类型 字符串 1.列举python中的基本数据类型 数字:int 布尔值:bool 字符串:str 列表:list 元组:tuple 字典:dict 集合:set 然后我们需要了解一些运算符,应为 ...
- selenium webdriver 相关网站
ITeye:http://shijincheng0223.iteye.com/blog/1481446 http://ztreeapi.iteye.com/blog/1750554 http://sm ...
- Vue - 动态绑定class
<div :class="{active:item.index==1}" > </div>
- SpringBoot之日志记录-专题四
SpringBoot之日志记录-专题四 六.日志管理 6.1使用log4j记录日志 6.1.2新建log4j配置文件 文件名称log4j.properties #log4j.rootLogger=CO ...
- Ubuntu 解决TXT文本乱码问题
只要依次在终端输入这两行指令即可: gsettings set org.gnome.gedit.preferences.encodings auto-detected "['GB18030' ...
- C#调用Win32 的API函数--User32.dll ----转载
Win32的API函数是微软自己的东西,可以直接在C#中直接调用,在做WinForm时还是很有帮助的.有时候我们之直接调用Win32 的API,可以很高效的实现想要的效果. using System; ...
- JuJu团队1月10号工作汇报
JuJu团队1月10号工作汇报 JuJu Scrum 团队成员 今日工作 剩余任务 困难 飞飞 fix出现的bug -- 无 婷婷 完善main.jl 训练流程 -- 无 恩升 绘图 -- 无 金 ...