程序生成的zip在pc上无效,但在android上无效
已解决: 好吧,所以我基本上是愚蠢的。我无法打开文件,因为我忘记安装winrar或7zip,因为这台电脑是新格式化的。。。一切正常。对不起,浪费了大家的时间 在我的应用程序中,我通过编程从目录中的照片和.csv文件生成一个.zip文件 它创建zip,然后发送带有附件的电子邮件,而不需要打嗝。但问题是,在我的电脑上,我无法提取.zip文件,因为它说它无效,但在我的设备上,使用“WinZip”,我可以检查我的.zip文件,它拥有它应该拥有的一切。这让我很困惑 这是我的密码: 在这里,我检查哪些复选框已被选中,然后做拉链程序生成的zip在pc上无效,但在android上无效,android,zip,zipoutputstream,Android,Zip,Zipoutputstream,已解决: 好吧,所以我基本上是愚蠢的。我无法打开文件,因为我忘记安装winrar或7zip,因为这台电脑是新格式化的。。。一切正常。对不起,浪费了大家的时间 在我的应用程序中,我通过编程从目录中的照片和.csv文件生成一个.zip文件 它创建zip,然后发送带有附件的电子邮件,而不需要打嗝。但问题是,在我的电脑上,我无法提取.zip文件,因为它说它无效,但在我的设备上,使用“WinZip”,我可以检查我的.zip文件,它拥有它应该拥有的一切。这让我很困惑 这是我的密码: 在这里,我检查哪些复选框
for(int i = 0; i < cbStates.size(); ++i)
{
if(cbStates.get(i))
{
String zipFile = Environment.getExternalStorageDirectory() + "/ArcFlash/" + listItems.get(i) + ".zip";//ex: /storage/sdcard0/ArcFlash/study12.zip
String srcDir = Environment.getExternalStorageDirectory() + "/ArcFlash/" + listItems.get(i);
try
{
FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos);
File srcFile = new File(srcDir);
Log.i("customException", "going to compress");
addDirToArchive(zos, srcFile);
// close the ZipOutputStream
zos.close();
}
catch (IOException ioe)
{
System.out.println("Error creating zip file: " + ioe);
}
//Send the email
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/image");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"jbasson@powercoreeng.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App");
String folderPath = Environment.getExternalStorageDirectory() + "/ArcFlash/" + listItems.get(i) + ".zip";
//Uri u = Uri.fromFile(folderPath);
//Log.i("customException", "uri path: " + u.getPath());
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + folderPath));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Toast.makeText(context,"Case \"" + studyName + "\" has been sent", Toast.LENGTH_LONG).show();
//adapter.setElement(i, adapter.getStudy(i) + "(sent)");
}
}
for(int i=0;i
这里是zip函数:
private static void addDirToArchive(ZipOutputStream zos, File srcFile)
{
File[] files = srcFile.listFiles();
Log.i("customException", "Adding directory: " + srcFile.getName());
for (int i = 0; i < files.length; i++)
{
// if the file is directory, use recursion
if (files[i].isDirectory())
{
addDirToArchive(zos, files[i]);
continue;
}
try
{
System.out.println("tAdding file: " + files[i].getName());
// create byte buffer
byte[] buffer = new byte[2048];//1024
FileInputStream fis = new FileInputStream(files[i]);
zos.putNextEntry(new ZipEntry(files[i].getAbsolutePath() + "/" + files[i].getName()));//files[i].getName()
int length;
while ((length = fis.read(buffer)) > 0)
{
zos.write(buffer, 0, length);
}
zos.closeEntry();
// close the InputStream
fis.close();
}
catch (Exception ex)
{
Log.i("customException", "error zipping: " + ex.getMessage());
}
}
}
private static void addDirToArchive(ZipOutputStream zos,文件srcFile)
{
File[]files=srcFile.listFiles();
Log.i(“customException”,“添加目录:”+srcFile.getName());
对于(int i=0;i0)
{
写入(缓冲区,0,长度);
}
zos.closeEntry();
//关闭输入流
fis.close();
}
捕获(例外情况除外)
{
Log.i(“customException”,“错误压缩:”+ex.getMessage());
}
}
}
好吧,我基本上很笨。我无法打开文件,因为我忘记安装winrar或7zip,因为这台电脑是新格式化的