Advertisement
radoslav1992

Untitled

Apr 1st, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. public static void generateJarFile(String from, String location, String name) throws IOException {
  2.     String myJarPath = location + name + ".jar";
  3.     File file = new File(myJarPath);
  4.     JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(file));
  5.  
  6.     File[] toInputFiles = new File(from).listFiles();
  7.  
  8.     assert toInputFiles != null;
  9.     for (File singleFile : toInputFiles) {
  10.         JarEntry jarEntry = new JarEntry(singleFile.getPath());
  11.         jarOutputStream.putNextEntry(jarEntry);
  12.         InputStream inputStream = new FileInputStream(singleFile);
  13.  
  14.         jarOutputStream.write(inputStream.read());
  15.         inputStream.close();
  16.     }
  17.     jarOutputStream.close();
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement