Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 820961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:33:47+00:00 2026-05-15T02:33:47+00:00

What is the Java equivalent to this jar command: C:\>jar cvf myjar.jar directory I’d

  • 0

What is the Java equivalent to this jar command:

C:\>jar cvf myjar.jar directory

I’d like to create this jar file programmatically as I can’t be assured that the jar command will be on the system path where I could just run the external process.

Edit: All I want is to archive (and compress) a directory. Doesn’t have to follow any java standard. Ie: a standard zip is fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:33:48+00:00Added an answer on May 15, 2026 at 2:33 am
    // These are the files to include in the ZIP file
        String[] source = new String[]{"source1", "source2"};
    
        // Create a buffer for reading the files
        byte[] buf = new byte[1024];
    
        try {
            // Create the ZIP file
            String target = "target.zip";
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(target));
    
            // Compress the files
            for (int i=0; i<source.length; i++) {
                FileInputStream in = new FileInputStream(source[i]);
    
                // Add ZIP entry to output stream.
                out.putNextEntry(new ZipEntry(source[i]));
    
                // Transfer bytes from the file to the ZIP file
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
    
                // Complete the entry
                out.closeEntry();
                in.close();
            }
    
            // Complete the ZIP file
            out.close();
        } catch (IOException e) {
        }
    

    You can also use the answer from this post How to use JarOutputStream to create a JAR file?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 493k
  • Answers 493k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't think the property needs to be mapped with… May 16, 2026 at 10:53 am
  • Editorial Team
    Editorial Team added an answer Thanks for all the suggestions, guys. It turns out that… May 16, 2026 at 10:53 am
  • Editorial Team
    Editorial Team added an answer Well, here is a solution. In short, you can subclass… May 16, 2026 at 10:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I was wondering if scala had an equivalent to java's @SuppressWarnings that can be
I know that you can use java.util.Properties to read Java properties files. See: Java
I am porting some Java code to C# and I ran across this: List<?>
Is there an equivalent to Python's popen2 in Java?
I'm a .Net developer, but for my current project I have to create some
I'm writing a java app using eclipse which references a few external jars and
In Ruby I frequently use File.dirname(__FILE__) to open configuration files and such. For those
I'm building a Java application (using Ant with build.xml and build.property files). Now I'd
I'm in the process of migrating some of our old code into Java and
I attempted to open a Java bug last Halloween. I immediately got a response

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.