I want to make a project to Download file And extract files. I tried fix it so long time. Please looking my Code and help me please, Or someone tell me how to download file and extrack zip file. In file "download.zip" contains 5 video files. I use Class Decompress from Sreedev R
public class MainActivity extends AppCompatActivity {
private static String dirPath, dirPath2;
final String URL1 = "http://webmaster.com/01/defualt.zip";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dirPath = Utils.getRootDirPath(getApplicationContext());
dirPath2 = Utils.getRootDirPath(getApplicationContext())+"Unzip";
init();
onClickListenerOne();
Decompress unzip = new Decompress(dirPath+"/download.zip",dirPath2);
unzip.unzip();
}
Decompress Class
public class Decompress {
private String zip;
private String loc;
public Decompress(String zipFile, String location) {
zip = zipFile;
loc = location;
dirChecker("");
}
public void unzip() {
try {
FileInputStream fin = new FileInputStream(zip);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if(ze.isDirectory()) {
dirChecker(ze.getName());
} else {
FileOutputStream fout = new FileOutputStream(loc + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read()) {
fout.write(c);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
}
private void dirChecker(String dir) {
File f = new File(loc + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
}