Programmatically generated zip invalid on pc but not on android -


solved: ok stupid. couldn't open file because forgot install winrar or 7zip since pc newly formatted... works fine. sorry waste anyone's time.

in app programmatically generate .zip file photos , .csv files in directory.

it creates zip , sends email attachment without hickup. problem on pc can't extract .zip file because says it's invalid, on device using "winzip" can check .zip file , has suppose have. confusing me.

here code: here check checkboxes have been checked zipping

for(int = 0; < 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 compress");                         adddirtoarchive(zos, srcfile);                          // close zipoutputstream                         zos.close();                     }                      catch (ioexception ioe)                     {                         system.out.println("error creating zip file: " + ioe);                     }                      //send 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 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)");                 }             } 

and here zip function:

private static void adddirtoarchive(zipoutputstream zos, file srcfile) {     file[] files = srcfile.listfiles();      log.i("customexception", "adding directory: " + srcfile.getname());      (int = 0; < files.length; i++)     {         // if file 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 inputstream             fis.close();         }         catch (exception ex)         {             log.i("customexception", "error zipping: " + ex.getmessage());         }     } } 

ok stupid. couldn't open file because forgot install winrar or 7zip since pc newly formatted...


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -