assert文件夹 设置android_android使用build.xml配置assert文件中不压缩的类型文件
問題:
在做文本文件讀取時,從assert文件中獲取文件
getResources().getAssets().openFd("test.txt").getFileDescriptor()
會報錯,提示File not Found ,because the file compressed,查找了很多資料,android打包成apk時,在assert文件中,除了音視頻文件不壓縮外,像txt之類的會進行壓縮成zip包,以節(jié)約空間,所以getFileDescriptor()時獲取不到,
通用都是獲取文件流,但在做大文件讀取時,最新技術(shù)推薦使用java nio中內(nèi)存映射技術(shù)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}">
總結(jié)
以上是生活随笔為你收集整理的assert文件夹 设置android_android使用build.xml配置assert文件中不压缩的类型文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: apache服务器配置tls_Apach
- 下一篇: 函数的梯度方向和切线方向_高数下微课:1