开发者

how to copy 15Mb files from assets folder to sdcard...?

I have 15Mb database files and i want to use in my application. i stored that file in assets folder. because of that large size file of 15Mb i cant copy that file to sdcard. i have tried all the things.. Is there any limitation to read file using input stream. my code is work well for up to 1Mb size data file but it not support for larger than 3to4 Mb. i making my file zip and then store into assets folder开发者_JS百科.

Here`s my code:

private Thread thread = new Thread()
    {

        @Override
        public void run()
        {


            // Create a directory in the SDCard to store the files
            File file = new File(ROOT_FOLDER);
            if (!file.exists())
            {
                file.mkdirs();
            }
            else
            {
                file.delete();
            }
            try
            {
                // Open the ZipInputStream
               ZipInputStream in = new ZipInputStream(getAssets().open("lds_scriptures.zip"));


                // Loop through all the files and folders
                for (ZipEntry entry = in.getNextEntry(); entry != null; entry = in
                        .getNextEntry())
                {
                    sendMessage("Extracting: " + entry.getName() + "...");

                    String innerFileName = ROOT_FOLDER + File.separator + entry.getName();
                    File innerFile = new File(innerFileName);
                    if (innerFile.exists())
                    {
                        innerFile.delete();
                    }

                    int size=in.available();
                    //Toast.makeText(SdCardData.this, String.valueOf(size),2000).show();
                    Log.e("value",String.valueOf(size));
                    // Check if it is a folder
                    if (entry.isDirectory())
                    {
                        // Its a folder, create that folder
                        innerFile.mkdirs();
                    }
                    else
                    {
                        // Create a file output stream
                        FileOutputStream outputStream = new FileOutputStream(innerFileName);
                        final int BUFFER = 2048;

                        // Buffer the ouput to the file
                        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream,
                                BUFFER);


                        // Write the contents
                        int count = 0;
                        byte[] data = new byte[BUFFER];
                        while ((count = in.read(data, 0, BUFFER)) != -1)
                        {
                            bufferedOutputStream.write(data, 0, count);
                        }

                        // Flush and close the buffers
                        bufferedOutputStream.flush();
                        bufferedOutputStream.close();
                    }
                 //   sendMessage("DONE");

                    // Close the current entry
                    in.closeEntry();
                }
                in.close();
               // sendMessage("-----------------------------------------------");
             //   sendMessage("Unzipping complete");

            }
            catch (IOException e)
            {
                sendMessage("Exception occured: " + e.getMessage());
                e.printStackTrace();
            }
        }

    };

    private Handler handler = new Handler()
    {

       // @Override
        public void handleMessage(Message msg)
        {
           // tv.append("\n" + msg.getData().getString("data"));
           // super.handleMessage(msg);
        }

    };

    private void sendMessage(String text)
    {
        Message message = new Message();
        Bundle data = new Bundle();
        data.putString("data", text);
        message.setData(data);
        handler.sendMessage(message);
    }


Maybe you're running out of memory. Try removing the entry object at the end of each iteration.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜