in Education by
I have a question that seems easy but I cannot seem to get it to work properly. I have a zip file within my 'assets' folder that I need to unzip and I have a ProgessBar in which I want to display to the user how the progress is going. I have everything working but I want to set the ProgessBar max value to be the number of files within the zip file. The number of files within this folder will sometimes change so I want the ProgessBar to be relative to how many files are contained within the zip. I'm using the ZipInputStream-API but does not seem there is a way to get the number of files within the zip file. The only way I can of think of is doing this: ZipInputStream zin = new ZipInputStream(getAssets().open( "myFile.zip")); int numFiles = 0; int increment = 0; while (zin.getNextEntry() != null) { numFiles++; } ZipEntry ze = null; //Set the Max..value here.. progessBar.setMax(numFiles); while ((ze = zin.getNextEntry()) != null) { increment++; progessBar.setProgress(increment); } This works but having two while loops seems a bit redundant which are basically doing the same thing. I know that there is a ZipFile-API which has a size()-method, but it requires a path to the file and since my file is located within the 'assets' folder I am pretty sure the only way to read from this directory is by streaming. Is there a way for me to accomplish this? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Thanks for the answers. What I ended up doing using the: AssetFileDescriptor API to get the file size of the zip file and setting that as the ProgessBar.setMax() value. Then as I loop through the zip contents I increment the progress by using each entries file size. This works but the only concern I have is that the AssetFileDescriptor.getLength() value as well as the ZipEntry.getSize() values return a long value so I am forced to cast them to an integer before I can set the max and/or increment the ProgessBar so there is a slight possibility I might overload an integer value causing an exception but this is not likely because I do not anticipate my file sizes ever getting bigger than the max holding capacity of an integer. ZipInputStream zin = new ZipInputStream(getAssets().open( "myFile.zip")); ZipEntry ze = null; AssetFileDescriptor mydisc = getAssets().openFd("myFile.zip"); //Size of the zip package long size = mydisc.getLength(); long increment = 0; dialog.setMax((int) size); while ((ze = zin.getNextEntry()) != null) { increment += (int) ze.getSize(); progessBar.setProgess((int)increment); //do more stuff.. } Not the best solution but it works. I'm aware of the ZipFile API but it requires a string to be passed in but I am not sure what the path is to that directory or how to get it?

Related questions

0 votes
    I made a website and turned it into Android app, using Phonegap website. I have files stored on a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    I am trying to use design support library. Gradle dependencies are as follows dependencies { compile 'com. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I am trying to use design support library. Gradle dependencies are as follows dependencies { compile 'com. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    I am trying to use design support library. Gradle dependencies are as follows dependencies { compile 'com. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    My application is receiving email through SMTP server. There are one or more attachments in the email and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Can we deploy Azure Functions referencing a zip file with relative path?...
asked Mar 10, 2021 in Technology by JackTerrance
0 votes
    I've got a flow where I want a codepipeline to trigger on git commits on Github, go via some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm using TensorFlow Alpha 2.0. I have TFRecords files I'm reading from, each one holding a short ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    How can I find out the instance id of an ec2 instance from within the ec2 instance? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    I am seeking an Android solution to calculate the distance to an object and then determine the size (height ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    i have been trying to make such a demo where i need to draw many(hundreds of) circle shapes on ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
...