从资产文件夹中加载大于1M的文件。

时间:2021-05-18 00:26:18

I'm going crazy, I created a file object, so it can be read with ObjectInputStream, and I placed the assets folder. The method works with a file smaller than 1M, and give error with larger files. I read that is a limit of Android platform, but I also know that can be "easily" avoided. Those who have downloaded the game Reging Thunder, for example, can easily see that in their assets folder is a file 18.9M large. This is my code for read 1 object from a ObjecInputStream

我疯了,我创建了一个file对象,所以可以用ObjectInputStream读取它,然后我放置了assets文件夹。该方法对小于1M的文件进行处理,对较大的文件进行错误处理。我读到这是Android平台的一个限制,但我也知道可以“轻松”避免。例如,那些下载了《Reging Thunder》游戏的用户可以很容易地看到,他们的assets文件夹里有一个18.9米大的文件。这是我从ObjecInputStream读取1对象的代码。

File f = File.createTempFile("mytempfile", "dat");
FileOutputStream fos = new FileOutputStream(f);

InputStream is = mc.getAssets().open(path,3);

ObjectInputStream ois=new ObjectInputStream(is);
byte[] data = (byte[]) ois.readObject();
fos.write(data);

fos.flush();
fos.close();
ois.close();
is.close();

now I have an uncompressed file and I can use it without worrying about the error "This file can not be opened as a file descriptor; it is probably compressed"

现在我有一个未压缩的文件,我可以使用它而不用担心错误“这个文件不能作为文件描述符打开;这可能是压缩”

This function works well with files smaller than 1M, with bigger files return an java.io.IOException on line "ObjectInputStream ois=new ObjectInputStream(is);"

这个函数可以很好地处理小于1M的文件,较大的文件返回java.io。“ObjectInputStream ois=new ObjectInputStream(is)”

why??

为什么? ?

11 个解决方案

#1


48  

Faced the same issue. I've cut up my 4MB file into 1 MB chunks, and on the first run I join the chunks into a data folder on the phone. As an added bonus, the APK is properly compressed. The chunk files are called 1.db, 2.db, etc. The code goes like this:

面临同样的问题。我将我的4MB文件分割成1 MB的块,在第一次运行时,我将这些块加入到电话的数据文件夹中。作为额外的奖励,APK被适当压缩。块文件称为1。db 2。代码是这样的:

File Path = Ctxt.getDir("Data", 0);
File DBFile = new File(Path, "database.db");

if(!DBFile.exists() || DatabaseNeedsUpgrade)  //Need to copy...
    CopyDatabase(Ctxt, DBFile);


static private void CopyDatabase(Context Ctxt, File DBFile) throws IOException
{
    AssetManager assets = Ctxt.getAssets();
    OutputStream outstream = new FileOutputStream(DBFile);
    DBFile.createNewFile();
    byte []b = new byte[1024];
    int i, r;
    String []assetfiles = assets.list("");
    Arrays.sort(assetfiles);
    for(i=1;i<10;i++) //I have definitely less than 10 files; you might have more
    {
        String partname = String.format("%d.db", i);
        if(Arrays.binarySearch(assetfiles, partname) < 0) //No such file in assets - time to quit the loop
            break;
        InputStream instream = assets.open(partname);
        while((r = instream.read(b)) != -1)
            outstream.write(b, 0, r);
        instream.close();
    }
    outstream.close();
}

#2


32  

The limitation is on compressed assets. If the asset is uncompressed, the system can memory-map the file data and use the Linux virtual memory paging system to pull in or discard 4K chunks as appropriate. (The "zipalign" tool ensures that uncompressed assets are word-aligned in the file, which means they'll also be aligned in memory when directly mapped.)

限制在压缩资产上。如果资产未被压缩,系统可以内存映射文件数据,并使用Linux虚拟内存分页系统根据需要提取或丢弃4K块。(“zipalign”工具确保未压缩的资产在文件中是字对齐的,这意味着它们在直接映射时也会在内存中对齐。)

If the asset is compressed, the system has to uncompress the entire thing to memory. If you have a 20MB asset, that means 20MB of physical memory is tied up by your application.

如果资产被压缩,系统必须将整个东西解压到内存中。如果您有一个20MB的资产,这意味着20MB的物理内存被应用程序绑定。

Ideally the system would employ some sort of windowed compression, so that only parts need to be present, but that requires some fanciness in the asset API and a compression scheme that works well with random access. Right now APK == Zip with "deflate" compression, so that's not practical.

理想情况下,系统将采用某种窗口压缩,因此只需要部分存在,但这需要资产API中的一些花哨,以及一个适用于随机访问的压缩方案。现在APK == Zip压缩压缩,所以这是不实际的。

You can keep your assets uncompressed by giving them a suffix of a file type that doesn't get compressed (e.g. ".png" or ".mp3"). You may also be able to add them manually during the build process with "zip -0" instead of having them bundled up by aapt. This will likely increase the size of your APK.

你可以给你的资产加上一个不会被压缩的文件类型的后缀(例如。”。png”或“mp3”)。您也可以在构建过程中使用“zip -0”手动添加它们,而不是由aapt打包它们。这可能会增加APK的大小。

#3


8  

Like Seva suggested you can split up your file in chunks. I used this to split up my 4MB file

就像Seva建议的那样,你可以将文件分割成块。我用它来分割我的4MB文件

public static void main(String[] args) throws Exception {  
    String base = "tracks";  
    String ext = ".dat";  
    int split = 1024 * 1024;  
    byte[] buf = new byte[1024];  
    int chunkNo = 1;  
    File inFile = new File(base + ext);  
    FileInputStream fis = new FileInputStream(inFile);  
    while (true) {  
      FileOutputStream fos = new FileOutputStream(new File(base + chunkNo + ext));  
      for (int i = 0; i < split / buf.length; i++) {  
        int read = fis.read(buf);  
        fos.write(buf, 0, read);  
        if (read < buf.length) {  
          fis.close();  
          fos.close();  
          return;  
        }  
      }  
      fos.close();  
      chunkNo++;  
    }  
  }  

If you do not need to combine the files into a single file on the device again, just use this InputStream, which combines them into one on the fly.

如果您不需要再次将这些文件合并到设备上的单个文件中,只需使用这个InputStream,它将这些文件动态地合并到一个文件中。

import java.io.IOException;  
import java.io.InputStream;  

import android.content.res.AssetManager;  

public class SplitFileInputStream extends InputStream {  

  private String baseName;  
  private String ext;  
  private AssetManager am;  
  private int numberOfChunks;  
  private int currentChunk = 1;  
  private InputStream currentIs = null;  

  public SplitFileInputStream(String baseName, String ext, int numberOfChunks, AssetManager am) throws IOException {  
    this.baseName = baseName;  
    this.am = am;  
    this.numberOfChunks = numberOfChunks;  
    this.ext = ext;  
    currentIs = am.open(baseName + currentChunk + ext, AssetManager.ACCESS_STREAMING);  
  }  

  @Override  
  public int read() throws IOException {  
    int read = currentIs.read();  
    if (read == -1 && currentChunk < numberOfChunks) {  
      currentIs.close();  
      currentIs = am.open(baseName + ++currentChunk + ext, AssetManager.ACCESS_STREAMING);  
      return read();  
    }  
    return read;  
  }  

  @Override  
  public int available() throws IOException {  
    return currentIs.available();  
  }  

  @Override  
  public void close() throws IOException {  
    currentIs.close();  
  }  

  @Override  
  public void mark(int readlimit) {  
    throw new UnsupportedOperationException();  
  }  

  @Override  
  public boolean markSupported() {  
    return false;  
  }  

  @Override  
  public int read(byte[] b, int offset, int length) throws IOException {  
    int read = currentIs.read(b, offset, length);  
    if (read < length && currentChunk < numberOfChunks) {  
      currentIs.close();  
      currentIs = am.open(baseName + ++currentChunk + ext, AssetManager.ACCESS_STREAMING);  
      read += read(b, offset + read, length - read);  
    }  
    return read;  
  }  

  @Override  
  public int read(byte[] b) throws IOException {  
    return read(b, 0, b.length);  
  }  

  @Override  
  public synchronized void reset() throws IOException {  
    if (currentChunk == 1) {  
      currentIs.reset();  
    } else {  
      currentIs.close();  
      currentIs = am.open(baseName + currentChunk + ext, AssetManager.ACCESS_STREAMING);  
      currentChunk = 1;  
    }  
  }  

  @Override  
  public long skip(long n) throws IOException {  
    long skipped = currentIs.skip(n);  
    if (skipped < n && currentChunk < numberOfChunks) {  
      currentIs.close();  
      currentIs = am.open(baseName + ++currentChunk + ext, AssetManager.ACCESS_STREAMING);  
      skipped += skip(n - skipped);  
    }  
    return skipped;  
  }  
}

Usage:
ObjectInputStream ois = new ObjectInputStream(new SplitFileInputStream("mytempfile", ".dat", 4, getAssets()));

用法:ObjectInputStream ois = new ObjectInputStream(新的SplitFileInputStream(“mytempfile”)。dat”4 getAssets()));

#4


7  

une methode pas propre consiste a changer extention du fichier ttf a mp3

一个方法不支持改变一个mp3格式的扩展

#5


2  

I know this is an old question but I thought of a good solution. Why not store the file already pre-zipped in the asset folder. Then since it is already a zip file and therefore compressed it won't need to be compressed again. So if you wanted the file to be compressed to decrease the size of your apk but you don't want to deal with splitting up files I think this is easier.

我知道这是个老问题,但我想到了一个好办法。为什么不将已预压缩的文件存储在asset文件夹中呢?然后,由于它已经是一个zip文件,因此被压缩了,因此不需要再次压缩它。如果你想要压缩文件来减小apk的大小但是你不想处理分割文件,我觉得这更简单。

When you need to read that file off the device just wrap the inputstream in a zipinputstream http://developer.android.com/reference/java/util/zip/ZipInputStream.html

当您需要从设备上读取该文件时,只需将inputstream包装为zipinputstream http://developer.android.com/reference/java/util/zip/ZipInputStream.html

#6


2  

I found another solution, maybe you're interested in it.

我找到了另一种解决办法,也许你会感兴趣。

In the root of your sources, where you have the build.xml file, you can overwrite the -package-resources target in the custom_rules.xml file, which is used for adding/modifying targets in ant without breaking anything in the standard android app build system.

在源代码的根中,有构建。xml文件,您可以在custom_rules中覆盖-package-resources目标。xml文件,用于在ant中添加或修改目标,而不会破坏标准android应用程序构建系统中的任何内容。

Just create a file with this content:

只需创建一个包含以下内容的文件:

<?xml version="1.0" encoding="UTF-8"?>
<project name="yourAppHere" default="help">

    <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 /> <!-- 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>
</project>

#7


0  

add file extension is mp3.I use mydb.mp3in assets folder and copy .this run without error.show check it.

添加文件扩展名是mp3。我使用mydb。mp3in资产文件夹和拷贝。这运行没有错误。显示检查它。

#8


0  

Using GZIP would be another method. you only need to wrap InputStream inside GZIPInputStream.

I used this for a database which size about 3.0 MB and output compress file was about 600KB.

使用GZIP是另一种方法。您只需将InputStream包装到GZIPInputStream中。我将它用于一个大小为3.0 MB、输出压缩文件大小为600KB的数据库。

  • For copying DB in firs run, I gzipped my source .db file using GZIP tool.
  • 为了在firs运行中复制DB,我使用GZIP工具压缩了源. DB文件。
  • Then renamed it to .jpg in order to avoid more compression (these processes are done before compile APK FILE).
  • 然后将其重命名为.jpg,以避免更多的压缩(这些过程在编译APK文件之前完成)。
  • Then for reading compressed GZIP file from assetss
  • 然后从assetss中读取压缩的GZIP文件

and copying it:

和复制:

private void copydatabase() throws IOException {
        // Open your local db as the input stream
        InputStream myinput = mContext.getAssets().open(DB_NAME_ASSET);
        BufferedInputStream buffStream = new BufferedInputStream(myinput);
        GZIPInputStream zis = new GZIPInputStream(buffStream);

        // Path to the just created empty db
        String outfilename = DB_PATH + DB_NAME;

        // Open the empty db as the output stream
        OutputStream myoutput = new FileOutputStream(outfilename);


        // transfer byte to inputfile to outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = zis.read(buffer)) > 0) {
            myoutput.write(buffer, 0, length);
        }

        // Close the streams
        myoutput.flush();
        myoutput.close();
        zis.close();
        buffStream.close();
        myinput.close();
    }

#9


0  

set database to multiple part with a program e.g "Win Hex", you can download from Link

使用程序e将数据库设置为多个部分。g“Win Hex”,你可以从链接下载。

and continue Load files bigger than 1M from assets folder

并继续从assets文件夹中加载大于1M的文件

#10


0  

Instead of assets folder, I have put my large files in the raw folder. It works for me.

我将大文件放在原始文件夹中,而不是assets文件夹。它适合我。

#11


-1  

I use NetBeans to build the package and I not found how to change the settings of AAPT. I have not tried the png, but the mp3 are compressed. I can compile the package and then enter the assets folder with the parameter -0? what would be the correct command to use?

我使用NetBeans来构建包,我没有发现如何更改AAPT的设置。我还没试过png,但是mp3已经压缩了。我可以编译这个包,然后输入参数-0的assets文件夹?使用的正确命令是什么?

#1


48  

Faced the same issue. I've cut up my 4MB file into 1 MB chunks, and on the first run I join the chunks into a data folder on the phone. As an added bonus, the APK is properly compressed. The chunk files are called 1.db, 2.db, etc. The code goes like this:

面临同样的问题。我将我的4MB文件分割成1 MB的块,在第一次运行时,我将这些块加入到电话的数据文件夹中。作为额外的奖励,APK被适当压缩。块文件称为1。db 2。代码是这样的:

File Path = Ctxt.getDir("Data", 0);
File DBFile = new File(Path, "database.db");

if(!DBFile.exists() || DatabaseNeedsUpgrade)  //Need to copy...
    CopyDatabase(Ctxt, DBFile);


static private void CopyDatabase(Context Ctxt, File DBFile) throws IOException
{
    AssetManager assets = Ctxt.getAssets();
    OutputStream outstream = new FileOutputStream(DBFile);
    DBFile.createNewFile();
    byte []b = new byte[1024];
    int i, r;
    String []assetfiles = assets.list("");
    Arrays.sort(assetfiles);
    for(i=1;i<10;i++) //I have definitely less than 10 files; you might have more
    {
        String partname = String.format("%d.db", i);
        if(Arrays.binarySearch(assetfiles, partname) < 0) //No such file in assets - time to quit the loop
            break;
        InputStream instream = assets.open(partname);
        while((r = instream.read(b)) != -1)
            outstream.write(b, 0, r);
        instream.close();
    }
    outstream.close();
}

#2


32  

The limitation is on compressed assets. If the asset is uncompressed, the system can memory-map the file data and use the Linux virtual memory paging system to pull in or discard 4K chunks as appropriate. (The "zipalign" tool ensures that uncompressed assets are word-aligned in the file, which means they'll also be aligned in memory when directly mapped.)

限制在压缩资产上。如果资产未被压缩,系统可以内存映射文件数据,并使用Linux虚拟内存分页系统根据需要提取或丢弃4K块。(“zipalign”工具确保未压缩的资产在文件中是字对齐的,这意味着它们在直接映射时也会在内存中对齐。)

If the asset is compressed, the system has to uncompress the entire thing to memory. If you have a 20MB asset, that means 20MB of physical memory is tied up by your application.

如果资产被压缩,系统必须将整个东西解压到内存中。如果您有一个20MB的资产,这意味着20MB的物理内存被应用程序绑定。

Ideally the system would employ some sort of windowed compression, so that only parts need to be present, but that requires some fanciness in the asset API and a compression scheme that works well with random access. Right now APK == Zip with "deflate" compression, so that's not practical.

理想情况下,系统将采用某种窗口压缩,因此只需要部分存在,但这需要资产API中的一些花哨,以及一个适用于随机访问的压缩方案。现在APK == Zip压缩压缩,所以这是不实际的。

You can keep your assets uncompressed by giving them a suffix of a file type that doesn't get compressed (e.g. ".png" or ".mp3"). You may also be able to add them manually during the build process with "zip -0" instead of having them bundled up by aapt. This will likely increase the size of your APK.

你可以给你的资产加上一个不会被压缩的文件类型的后缀(例如。”。png”或“mp3”)。您也可以在构建过程中使用“zip -0”手动添加它们,而不是由aapt打包它们。这可能会增加APK的大小。

#3


8  

Like Seva suggested you can split up your file in chunks. I used this to split up my 4MB file

就像Seva建议的那样,你可以将文件分割成块。我用它来分割我的4MB文件

public static void main(String[] args) throws Exception {  
    String base = "tracks";  
    String ext = ".dat";  
    int split = 1024 * 1024;  
    byte[] buf = new byte[1024];  
    int chunkNo = 1;  
    File inFile = new File(base + ext);  
    FileInputStream fis = new FileInputStream(inFile);  
    while (true) {  
      FileOutputStream fos = new FileOutputStream(new File(base + chunkNo + ext));  
      for (int i = 0; i < split / buf.length; i++) {  
        int read = fis.read(buf);  
        fos.write(buf, 0, read);  
        if (read < buf.length) {  
          fis.close();  
          fos.close();  
          return;  
        }  
      }  
      fos.close();  
      chunkNo++;  
    }  
  }  

If you do not need to combine the files into a single file on the device again, just use this InputStream, which combines them into one on the fly.

如果您不需要再次将这些文件合并到设备上的单个文件中,只需使用这个InputStream,它将这些文件动态地合并到一个文件中。

import java.io.IOException;  
import java.io.InputStream;  

import android.content.res.AssetManager;  

public class SplitFileInputStream extends InputStream {  

  private String baseName;  
  private String ext;  
  private AssetManager am;  
  private int numberOfChunks;  
  private int currentChunk = 1;  
  private InputStream currentIs = null;  

  public SplitFileInputStream(String baseName, String ext, int numberOfChunks, AssetManager am) throws IOException {  
    this.baseName = baseName;  
    this.am = am;  
    this.numberOfChunks = numberOfChunks;  
    this.ext = ext;  
    currentIs = am.open(baseName + currentChunk + ext, AssetManager.ACCESS_STREAMING);  
  }  

  @Override  
  public int read() throws IOException {  
    int read = currentIs.read();  
    if (read == -1 && currentChunk < numberOfChunks) {  
      currentIs.close();  
      currentIs = am.open(baseName + ++currentChunk + ext, AssetManager.ACCESS_STREAMING);  
      return read();  
    }  
    return read;  
  }  

  @Override  
  public int available() throws IOException {  
    return currentIs.available();  
  }  

  @Override  
  public void close() throws IOException {  
    currentIs.close();  
  }  

  @Override  
  public void mark(int readlimit) {  
    throw new UnsupportedOperationException();  
  }  

  @Override  
  public boolean markSupported() {  
    return false;  
  }  

  @Override  
  public int read(byte[] b, int offset, int length) throws IOException {  
    int read = currentIs.read(b, offset, length);  
    if (read < length && currentChunk < numberOfChunks) {  
      currentIs.close();  
      currentIs = am.open(baseName + ++currentChunk + ext, AssetManager.ACCESS_STREAMING);  
      read += read(b, offset + read, length - read);  
    }  
    return read;  
  }  

  @Override  
  public int read(byte[] b) throws IOException {  
    return read(b, 0, b.length);  
  }  

  @Override  
  public synchronized void reset() throws IOException {  
    if (currentChunk == 1) {  
      currentIs.reset();  
    } else {  
      currentIs.close();  
      currentIs = am.open(baseName + currentChunk + ext, AssetManager.ACCESS_STREAMING);  
      currentChunk = 1;  
    }  
  }  

  @Override  
  public long skip(long n) throws IOException {  
    long skipped = currentIs.skip(n);  
    if (skipped < n && currentChunk < numberOfChunks) {  
      currentIs.close();  
      currentIs = am.open(baseName + ++currentChunk + ext, AssetManager.ACCESS_STREAMING);  
      skipped += skip(n - skipped);  
    }  
    return skipped;  
  }  
}

Usage:
ObjectInputStream ois = new ObjectInputStream(new SplitFileInputStream("mytempfile", ".dat", 4, getAssets()));

用法:ObjectInputStream ois = new ObjectInputStream(新的SplitFileInputStream(“mytempfile”)。dat”4 getAssets()));

#4


7  

une methode pas propre consiste a changer extention du fichier ttf a mp3

一个方法不支持改变一个mp3格式的扩展

#5


2  

I know this is an old question but I thought of a good solution. Why not store the file already pre-zipped in the asset folder. Then since it is already a zip file and therefore compressed it won't need to be compressed again. So if you wanted the file to be compressed to decrease the size of your apk but you don't want to deal with splitting up files I think this is easier.

我知道这是个老问题,但我想到了一个好办法。为什么不将已预压缩的文件存储在asset文件夹中呢?然后,由于它已经是一个zip文件,因此被压缩了,因此不需要再次压缩它。如果你想要压缩文件来减小apk的大小但是你不想处理分割文件,我觉得这更简单。

When you need to read that file off the device just wrap the inputstream in a zipinputstream http://developer.android.com/reference/java/util/zip/ZipInputStream.html

当您需要从设备上读取该文件时,只需将inputstream包装为zipinputstream http://developer.android.com/reference/java/util/zip/ZipInputStream.html

#6


2  

I found another solution, maybe you're interested in it.

我找到了另一种解决办法,也许你会感兴趣。

In the root of your sources, where you have the build.xml file, you can overwrite the -package-resources target in the custom_rules.xml file, which is used for adding/modifying targets in ant without breaking anything in the standard android app build system.

在源代码的根中,有构建。xml文件,您可以在custom_rules中覆盖-package-resources目标。xml文件,用于在ant中添加或修改目标,而不会破坏标准android应用程序构建系统中的任何内容。

Just create a file with this content:

只需创建一个包含以下内容的文件:

<?xml version="1.0" encoding="UTF-8"?>
<project name="yourAppHere" default="help">

    <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 /> <!-- 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>
</project>

#7


0  

add file extension is mp3.I use mydb.mp3in assets folder and copy .this run without error.show check it.

添加文件扩展名是mp3。我使用mydb。mp3in资产文件夹和拷贝。这运行没有错误。显示检查它。

#8


0  

Using GZIP would be another method. you only need to wrap InputStream inside GZIPInputStream.

I used this for a database which size about 3.0 MB and output compress file was about 600KB.

使用GZIP是另一种方法。您只需将InputStream包装到GZIPInputStream中。我将它用于一个大小为3.0 MB、输出压缩文件大小为600KB的数据库。

  • For copying DB in firs run, I gzipped my source .db file using GZIP tool.
  • 为了在firs运行中复制DB,我使用GZIP工具压缩了源. DB文件。
  • Then renamed it to .jpg in order to avoid more compression (these processes are done before compile APK FILE).
  • 然后将其重命名为.jpg,以避免更多的压缩(这些过程在编译APK文件之前完成)。
  • Then for reading compressed GZIP file from assetss
  • 然后从assetss中读取压缩的GZIP文件

and copying it:

和复制:

private void copydatabase() throws IOException {
        // Open your local db as the input stream
        InputStream myinput = mContext.getAssets().open(DB_NAME_ASSET);
        BufferedInputStream buffStream = new BufferedInputStream(myinput);
        GZIPInputStream zis = new GZIPInputStream(buffStream);

        // Path to the just created empty db
        String outfilename = DB_PATH + DB_NAME;

        // Open the empty db as the output stream
        OutputStream myoutput = new FileOutputStream(outfilename);


        // transfer byte to inputfile to outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = zis.read(buffer)) > 0) {
            myoutput.write(buffer, 0, length);
        }

        // Close the streams
        myoutput.flush();
        myoutput.close();
        zis.close();
        buffStream.close();
        myinput.close();
    }

#9


0  

set database to multiple part with a program e.g "Win Hex", you can download from Link

使用程序e将数据库设置为多个部分。g“Win Hex”,你可以从链接下载。

and continue Load files bigger than 1M from assets folder

并继续从assets文件夹中加载大于1M的文件

#10


0  

Instead of assets folder, I have put my large files in the raw folder. It works for me.

我将大文件放在原始文件夹中,而不是assets文件夹。它适合我。

#11


-1  

I use NetBeans to build the package and I not found how to change the settings of AAPT. I have not tried the png, but the mp3 are compressed. I can compile the package and then enter the assets folder with the parameter -0? what would be the correct command to use?

我使用NetBeans来构建包,我没有发现如何更改AAPT的设置。我还没试过png,但是mp3已经压缩了。我可以编译这个包,然后输入参数-0的assets文件夹?使用的正确命令是什么?