How to copy 15Mb files from the resource folder to the SD card ...?

I have 15 MB database files and I want to use them in my application. I saved this file in the resource folder. because of this large 15 MB file, I cannot copy this file to an SDCard. I tried everything. Is there a restriction on reading a file using the input stream. my code works well for data files up to 1 MB in size, but it does not support more than 3to4 MB. I make my zip file and then save it in the resources folder.

Here is 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);
    }
+3
source share
2 answers
+2
source

, . entry .

0

Source: https://habr.com/ru/post/1790618/


All Articles