Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/msfJavaToolkit/javaCompile/CreateJarFile.java
Views: 11780
// Source: http://www.java2s.com/Code/Java/File-Input-Output/CreateJarfile.htm12package javaCompile;34import java.io.File;5import java.io.FileInputStream;6import java.io.FileOutputStream;7import java.util.jar.JarEntry;8import java.util.jar.JarOutputStream;9import java.util.jar.Manifest;1011public class CreateJarFile {12public static int BUFFER_SIZE = 10240;13public static void createJarArchive(File archiveFile, File[] tobeJared) {14try {15byte buffer[] = new byte[BUFFER_SIZE];16// Open archive file17FileOutputStream stream = new FileOutputStream(archiveFile);18JarOutputStream out = new JarOutputStream(stream, new Manifest());1920for (int i = 0; i < tobeJared.length; i++) {21if (tobeJared[i] == null || !tobeJared[i].exists()22|| tobeJared[i].isDirectory())23continue; // Just in case...24//System.out.println("Adding " + tobeJared[i].getName());2526// Add archive entry27JarEntry jarAdd = new JarEntry(tobeJared[i].getName());28jarAdd.setTime(tobeJared[i].lastModified());29out.putNextEntry(jarAdd);3031// Write file to archive32FileInputStream in = new FileInputStream(tobeJared[i]);33while (true) {34int nRead = in.read(buffer, 0, buffer.length);35if (nRead <= 0)36break;37out.write(buffer, 0, nRead);38}39in.close();40}4142out.close();43stream.close();44//System.out.println("Adding completed OK");45} catch (Exception ex) {46ex.printStackTrace();47System.out.println("Error: " + ex.getMessage());48}49}50}515253