I have a folder /mnt/sdcard/Bluetooth
which contains several zip
files. Each of this zip-files contains only one file. How can I extract the content for each of these zip-files into a new file, containing the content of each zip-file? This is what I've done so far:
public class Main extends Activity {
Object[] arrayOfRarFiles;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String path = "/mnt/sdcard/Bluetooth";
String nameOfFiles;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
nameOfFiles = listOfFiles[i].getName();
if (nameOfFiles.endsWith(".zip")
|| nameOfFiles.endsWith(".ZIP")) {
try {
extractFile(nameOfFiles);
} catch (FileNotFoundException e) {
Log.e("EXTRACTFILE SAYS: ", e.getMessage());
}
}
}
}
}
public void extractFile(String path) throws FileNotFoundException {
String zipFileName = "/mnt/sdcard/Bluetooth/" + path;
String extractedFileName = getApplicationContext().getFilesDir()
.getPath().toString()
+ "Finger.FIR";
ZipInputStream inStream = new ZipInputStream(new FileInputStream(
zipFileName));
OutputStream outStream = new FileOutputStream(extractedFileName);
Toast.makeText(getApplicationContext(), zipFileName,
Toast.LENGTH_SHORT).show();
}
The last toast, in the extractFile
method outputs the name of each zip-file. The file inside the zip-folders are .FIR
files