问题:
在做文本文件读取时,从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);
}
问题参考:
http://ponystyle.com/blog/2010/03/26/dealing-with-asset-compression-in-android-apps/
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, or aapt, 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, aapt selectively compresses various assets to save space on the device. The way aapt determines which assets need compression is by their file extension. The following code, taken from Package.cpp in the aaptsource 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
<!-- Puts the project's resources into the output package file
This actually can create multiple resource package in case
Some custom apk with specific configuration have been
declared in default.properties.
-->
<target name="-package-resources" depends="-crunch">
<!-- only package resources if *not* a library project -->
<do-only-if-not-library elseText="Library project: do not package resources..." >
<aapt executable="${aapt}"
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}">
<res path="${out.res.absolute.dir}" />
<res path="${resource.absolute.dir}" />
<nocompress extension="txt" />
<!-- <nocompress /> forces no compression on any files in assets or res/raw -->
<!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->
</aapt>
</do-only-if-not-library>
</target>
相关推荐
通过调用UnzipUtils下面的UnzipUtils.createFile(locationZip);UnzipUtils.copyBigDataToSD(MainActivity.this, locationZip, ZIP_NAME);UnzipUtils.upZipFile(new File(locationZip)...
junit.framework.Assert.class junit.framework.AssertionFailedError.class junit.framework.ComparisonCompactor.class junit.framework.ComparisonFailure.class junit.framework.JUnit4TestAdapter.class junit....
理解Gradle构建过程,解读Android Gradle插件的配置 阅读本文一定是要使用过Gradle生成apk,文中不会讲如何安装运行Gradle,如有需要可先看文末的参考文章。 APK包是一个ZIP压缩包,从Java源代码、资源文件到生成这...
Android读取Assert资源目录下数据库,数据库操作; Android读取Assert资源目录下数据库,数据库操作 Android读取Assert资源目录下数据库,数据库操作
assert.h头文件下载
Android 使用MediaPlayer播放assets或者raw目录的音频文件 https://blog.csdn.net/qq_31939617/article/details/80491552
断言回调一个插入式替换库,允许您在异步函数中使用断言,利用回调来处理错误。API 奇偶校验[X] ... assert(value, [message]) [X] ... assert.ok(value, [message]) [X] ... assert.equal(actual, expected, ...
android用webview加载assert中的html并且可拨打页面中的电话。
对于开始学vc的人,对于assert,assert_valid,verify,trace的宏感到很奇怪,总是觉得很难掌握似的,其实这些主要是没有理清楚他们各自宏之间深层次的意义。
适用于Java大部分非空判断,有效的减少空指针问题,直接调用Assert 里面的方法就行,非常方便,你值得拥有
让您一直使用Node.js 4.0 assert.deepStrictEqual() / assert.notDeepStrictEqual()方法一直返回到Node.js 0.10。 问题和改进应首先在完成。 安装 $ npm install --save core-assert 用法 var assert = require ...
赠送jar包:wildfly-common-1.5.2.Final.jar; 赠送原API文档:wildfly-common-1.5.2.Final-javadoc.jar; 赠送源代码:wildfly-common-...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
VC中如何使用ASSERT断言 VC中如何使用ASSERT断言
Android 加载assets文件夹的文本文件 图片
4. 可配置 "=" 两边需不需要空格等. 详情用法请见Test内容。 eg: CSimpleIniA ini; ini.SetUnicode(); SI_Error rc = ini.LoadFile("example.ini"); if (rc ) { /* handle error */ }; ASSERT_EQ(rc, SI_OK)...
10、使用 final 关键字修饰一个变量时,是引用不能变,还是引用的对象不能变? .................................................................................................................................
refute 是“assert.not*”断言库。 它的灵感来自 。 安装 npm install --save-dev refute 用法 refute继承自 (Node's Assert)。 var assert = require("assert"); var refute = require("refute")(assert); ...
使用springboot框架快速搭建,封装自定义断言做业务校验,公共异常处理打印日志, 更简单的业务判断处理