| 44 | Desktop.getDesktop().browseFileDirectory(File(outputTo)) |
| 45 | } |
| 46 | |
| 47 | fun zipFiles(files: Collection<File>, output: String): Boolean { |
| 48 | |
| 49 | var fos: FileOutputStream? = null |
| 50 | try { |
| 51 | fos = FileOutputStream(output) |
| 52 | var zipOut = ZipOutputStream(BufferedOutputStream(fos)) |
| 53 | for (filePath in files) { |
| 54 | val input = filePath |
| 55 | var fis = FileInputStream(input) |
| 56 | val ze = ZipEntry(input.getName()) |
| 57 | zipOut.putNextEntry(ze) |
| 58 | val tmp = ByteArray(4 * 1024) |
| 59 | var size = 0 |
| 60 | while (true) { |
| 61 | size = fis.read(tmp) |
| 62 | if (size == -1) break; |
| 63 | |
| 64 | zipOut.write(tmp, 0, size) |
| 65 | } |
| 66 | zipOut.flush() |
| 67 | fis.close() |
| 68 | } |
| 69 | zipOut.close() |
| 70 | } catch (e: FileNotFoundException) { |
| 71 | e.printStackTrace() |
| 72 | return false |
| 73 | } catch (e: IOException) { |
| 74 | e.printStackTrace() |
| 75 | return false |
| 76 | } finally { |
| 77 | try { |
| 78 | if (fos != null) fos.close() |
| 79 | } catch (ex: Exception) { |
| 80 | ex.printStackTrace() |
| 81 | return false |
| 82 | } |
| 83 | } |
| 84 | return true |
| 85 | } |
| 86 | |
| 87 | } |