0
我有一个文件夹/mnt/sdcard/Bluetooth
其中包含几个zip
文件。每个zip文件只包含一个文件。如何将这些zip文件的内容解压缩到一个新文件中,其中包含每个zip文件的内容?这是我迄今所做的:从zip创建文件 - android
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();
}
最后敬酒,在extractFile
方法输出每个zip文件的名称。 zip文件夹内的文件是.FIR
文件
这样做的工作,但我无法找到使用Astro文件管理器我的解压缩文件。在代码中,我应该把提取的文件放在哪里? – 2012-07-26 13:21:09
他们应该在他们解压缩的路径。你有没有在那里检查? – 2012-07-26 13:47:47