Windows zip folder using command line

I am writing a program that should archive a file. This will work on both Linux and Windows machines. It works fine on Linux, but I can't do anything on Windows. I use the apache-net project to send commands. I also tried using Runtime (). Exec but it does not work. Can anyone suggest something?

CommandLine cmdLine = new CommandLine("zip");
     cmdLine.addArgument("-r");
     cmdLine.addArgument("documents.zip");
     cmdLine.addArgument("documents");
     DefaultExecutor exec = new DefaultExecutor();
     ExecuteWatchdog dog = new ExecuteWatchdog(60*1000);
     exec.setWorkingDirectory(new File("."));
     exec.setWatchdog(dog);
    int check =-1;
    try {
        check = exec.execute(cmdLine);
    } catch (ExecuteException e) {

    } catch (IOException e) {
    }
+3
source share
3 answers

Java java.util.zip. *, .zip. , . quickie, . Java , .

  public static void zip(String origFileName) {
    try {
      String zipName=origFileName + ".zip";
      ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipName)));
      byte[] data = new byte[1000]; 
      BufferedInputStream in = new BufferedInputStream(new FileInputStream(origFileName));
      int count;
      out.putNextEntry(new ZipEntry(origFileName));
      while((count = in.read(data,0,1000)) != -1) {  
        out.write(data, 0, count);
      }
      in.close();
      out.flush();
      out.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
+6

compact.exe / dos

NTFS.

COMPACT [/C |/U] [/S [: dir]] [/A] [/I] [/F] [/Q] [ [...]]

/C . , , , .

/U . , , , .

/S . "dir" - .

/A . .

/I . COMPACT .

/F , , . .

/Q .

filename , .

, COMPACT , . . .


.

compact file.txt

file.txt

compact file.txt/C

Contains file.txt file.

0
source

All Articles