问题:

在做文本文件读取时,从assert文件中获取文件

getResources().getAssets().openFd("test.txt").getFileDescriptor()

会报错,提示File not Found ,because the file compressed,查找了很多资料,android打包成apk时,在assert文件中,除了音视频文件不压缩外,像txt之类的会进行压缩成zip包,以节约空间,所以getFileDescriptor()时获取不到,

通用都是获取文件流,但在做大文件读取时,最新技术推荐使用java nio中内存映射技术MappedByteBuffer

public void openbook(FileDescriptor fileD) throws IOException {

//book_file = new File(strFilePath);

FileInputStream in=new FileInputStream(fileD);

long lLen = in.available();

m_mbBufLen = (int) lLen;

m_mbBuf =in.getChannel().map(

FileChannel.MapMode.READ_ONLY, 0, lLen);

}

问题参考:

When developing an Android app, any data file, image or XML file (that is, any Resource or Asset) you use is bundled into your application package (APK) for distribution. The Android Asset Packaging Tool, oraapt, is responsible for creating this bundle, which you can think of as a ZIP file with a particular layout that the Android OS can understand. When your application is installed, whether in development mode or by an end user, this APK file is simply dropped into a special location on the device’s (or emulator’s) filesystem.

As part of preparing your APK,aaptselectively compresses various assets to save space on the device. The wayaaptdetermines which assets need compression is by their file extension. The following code, taken fromPackage.cppin theaaptsource code, sheds some light on which types of files are not compressed by default:

/* these formats are already compressed, or don't compress well */

static const char* kNoCompressExt[] = {

".jpg", ".jpeg", ".png", ".gif",

".wav", ".mp2", ".mp3", ".ogg", ".aac",

".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",

".rtttl", ".imy", ".xmf", ".mp4", ".m4a",

".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",

".amr", ".awb", ".wma", ".wmv"

};

解决方案:

配置build.xml时配置不压缩txt文件

D:\android-eclipse\sdk\tools\ant

command="package"

versioncode="${version.code}"

versionname="${version.name}"

debug="${build.is.packaging.debug}"

manifest="${out.manifest.abs.file}"

assets="${asset.absolute.dir}"

androidjar="${project.target.android.jar}"

apkfolder="${out.absolute.dir}"

nocrunch="${build.packaging.nocrunch}"

resourcefilename="${resource.package.file.name}"

resourcefilter="${aapt.resource.filter}"

libraryResFolderPathRefid="project.library.res.folder.path"

libraryPackagesRefid="project.library.packages"

libraryRFileRefid="project.library.bin.r.file.path"

previousBuildType="${build.last.target}"

buildType="${build.target}"

ignoreAssets="${aapt.ignore.assets}">

assert文件夹 设置android_android使用build.xml配置assert文件中不压缩的类型文件相关推荐

  1. linux 家目录没有ssh文件夹,ssh – 如何远程列出已配置用户主目录中的目录

    我注意到当通过ssh对 Linux服务器进行单行处理时,〜的值仍然是本地用户主目录的值,而不是远程用户的主目录.见证本地用户dotancohen和远程用户atwood: $whoami dotanco ...

  2. IDEA如何将项目中文件夹设置为Sources(蓝色)

    问题描述 新建的文件夹不能new相关的类. 问题原因 文件夹没有被设置成Sources(蓝色)导致的. 解决办法 按照如下步骤,将文件夹设置成Sources(蓝色). Apply后,重新点击右键,可以 ...

  3. ubuntu java classpath_java – 如何为Ubuntu中的文件夹设置CLASSPATH变量

    我知道导出CLASSPATH = /usr/local/java / tools.jar:$CLASSPATH会将tools.jar添加到CLASSPATH,但我想将文件夹设置为CLASSPATH 像 ...

  4. IDEA添加eclispe的项目,需要把对应的文件夹设置成对应的资源

    第二步:找到自己对应的文件夹设置成对应的资源目录

  5. Windows加密文件夹设置

    想要对文件夹加密,Windows自带加密功能,如何使用Windows加密对文件夹设置密码?方法如下: 右键点击需要加密的文件夹,查看文件属性,在文件属性中点击高级 勾选上加密内容以便保护数据,点击确定 ...

  6. windows 文件夹设置 everyone 共享

    网络设置 打开网络共享中心 – 更改高级共享设置 – 公用 勾选:启用网络发现,启用文件和打印机共享,启用共享以便可以访问网络的用户可以读取和写入公用文件夹中的文件,关闭密码保护共享 本地组策略设置 ...

  7. win7在同一窗口打开文件夹设置失效

    文献参考 百度知道关于win7在同一窗口打开文件夹设置失效

  8. win10系统给文件夹设置备注

    文件详细信息 添加备注列. 右键 => 其他 => 找到□备注项,勾选 => 确认 创建文件夹配置文件. 打开需要配置备注的文件夹,右键新建[文本文档],打开新建的txt文件,粘贴下 ...

  9. PHPStorm 配置远程服务器文件夹在本地windows镜像,实现代码自动同步(类似于Samba架构文件同步功能)

    场景介绍: 这是一种类似samba架构,也和 filezilla+xshell 模式相类似的代码文件同步的模式,但是却更加优雅,也更加方便简洁. 环境介绍: 本地windows端:编辑器phpstor ...

最新文章

  1. BigInteger类实例的构造过程——JDK源码解析
  2. 《OpenACC并行程序设计:性能优化实践指南》一 3.5 在应用程序执行期间记录性能信息...
  3. 链表中是否存在环的问题,及环入口在链表中位置(Linked List Cycle II)
  4. 关于 create-react-app 自定义 eslint文件配置解决方案
  5. 线段覆盖(洛谷P1803题题解,C++语言描述)
  6. python的django框架http请求_python django框架(一)
  7. cocos2dx进阶学习之屏幕适配
  8. TLS总结(上)——我们为啥需要TLS
  9. 问题1:编译内核出现错误‘debian/stamp/build/kernel‘及解决方案
  10. 什么表示计算机的存储容量,存储容量
  11. TypeError parentComponent.ctx.deactivate is not a function
  12. 【Python】B样条曲线绘制
  13. Echarts双Y轴图表处理
  14. 云旗OS助手火了!可一站式体验统信UOS
  15. 微信公众号:设置分享
  16. Android音频系统之四AudioPolicy
  17. 最新友价T5商城系统源码/21个模板+新媒域名任务服务包
  18. 软件项目管理工具,JAVA WEB 框架技术(结合实际工作经验,全是干货)
  19. 视频聊天网站的研究、发展以及趋势(转)
  20. continue用法

热门文章

  1. 使用jmeter 设计流程发起测试
  2. Heap(堆结构/优先队列)-Swift实现
  3. 我为什么喜欢用C#来做并发编程
  4. Jenkins执行批处理文件失败
  5. VS中调试时不能关联源代码问题
  6. 无法将类型为“System.__ComObject”的 COM 对象强制转换为类类型“mshtml.HTMLInputElementClass...
  7. 在C#代码中应用Log4Net 中配置文件的解释
  8. Java中BigDecimal解决精度丢失问题
  9. Django_前端显示Matplotlib画的图(亲测)
  10. Python从数据库读取大量数据批量写入文件的方法