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

  • Home
  • SEARCH
  • 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 6928165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:08:56+00:00 2026-05-27T11:08:56+00:00

I am writing a java program on windows platform. I need to compress certain

  • 0

I am writing a java program on windows platform. I need to compress certain files into a zip archive. I am using ProcessBuilder to start a new 7zip process:

ProcessBuilder processBuilder = new ProcessBuilder("7Z","a",zipPath,filePath);
Process p = processBuilder.start();
p.waitFor();

The problem is that the 7zip process never exits after completion. It does create the required zip file but after that just hangs in there. This means that the waitFor() call never returns and my program gets stuck. Please suggest a fix or a work around.

  • 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-27T11:08:56+00:00Added an answer on May 27, 2026 at 11:08 am

    here is what I ended up doing.

    I can’t set enviroment variables so I had to set the c: path for 7zip.

        public void zipMultipleFiles (List<file> Files, String destinationFile){
            String zipApplication = "\"C:\\Program Files\7Zip\7zip.exe\" a -t7z"; 
            String CommandToZip = zipApplication + " ";    
            for (File file : files){
               CommandToZip = CommandToZip + "\"" + file.getAbsolutePath() + "\" ";
            }
            CommandToZip = CommandToZip + " -mmt -mx5 -aoa";
            runCommand(CommandToZip);
        }
    
        public void runCommand(String commandToRun) throws RuntimeException{
            Process p = null;
            try{
                p = Runtime.getRuntime().exec(commandToRun);
                String response = convertStreamToStr(p.getInputStream());
                p.waitFor();
            } catch(Exception e){
                throw new RuntimeException("Illegal Command ZippingFile");
            } finally {
                if(p = null){
                    throw new RuntimeException("Illegal Command Zipping File");
                }
                if (p.exitValue() != 0){
                    throw new Runtime("Failed to Zip File - unknown error");
                }
            }
        }
    

    The convert to string function can be found here which is what I used as a reference. http://singztechmusings.wordpress.com/2011/06/21/getting-started-with-javas-processbuilder-a-sample-utility-class-to-interact-with-linux-from-java-program/

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

Sidebar

Related Questions

I'm writing a cross-platform program in Java and want to stick the configuration files
I tried writing a program in Java using regex to match a pattern and
I am writing a program that needs to run a java.jar server. I need
I'm writing a Java program that will be used on both Windows and Mac.
I'm writing (under linux or windows+cygwin) a java program that needs to run a
In Java, of course. I'm writing a program and running it under a Windows
I am writing a Java Swing-based program using and JFrame that is able to
I am writing a java program to process direct payments using paypal. Naturally I
I am writing a java program that needs a file open dialog. The file
I am writing this java program to find all the prime numbers up to

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.