Compression Js-yuicompressor-2.4.jar

Source: Internet
Author: User

Import Java.io.BufferedReader;

Import Java.io.File;

Import Java.io.FileFilter;

Import java.io.IOException;

Import Java.io.InputStreamReader;


/**

* Compression JS

* Java-jar Yuicompressor-2.4.jar--type js xxx.js-o xxx.js--charset utf-8

* Compress CSS

* Java-jar yuicompressor-2.4.jar--type css xxx.css-o xxx.css--charset utf-8

* Java Runtime.getruntime (). EXEC (COMMANDSTR) can invoke the Execute CMD command.

* (1) cmd/c dir closes the command window after executing the dir command.

* (2) cmd/k dir does not close the command window after executing the dir command.

* (3) cmd/c start dir will open a new window and execute the dir instruction, the original window will be closed.

* (4) cmd/k start dir will open a new window and execute the dir instruction, the original window will not be closed.

* @author Ligang

* PS: When compressing CSS, it will affect JS and other types of files!!!

* Compression js, no problem, it is recommended to compress which type of file when the type of file placed!!!

*/

public class Zipjs {

public static void Main (string[] args) throws Exception {

File exists directory

String dir = "D:\\js";

string[] FileNames = GetFileNames (dir);

System.out.println ("The total number of files:" +filenames.length);

for (String string:filenames) {

if (String.Equals ("Yuicompressor-2.4.jar")) {

Continue;

}

String cmd = "Java-jar yuicompressor-2.4.jar--type js" +string+ "-o" +string+ "--charset utf-8";

String cmd = "Java-jar yuicompressor-2.4.jar--type css" +string+ "-o" +string+ "--charset utf-8";

Runtime.getruntime (). EXEC ("cmd/c D: & CD" +dir+ "&" +cmd);

}

}

Get all file names under the current folder

private static string[] GetFileNames (String dir) {

File File = new file (dir);

file[] files = file.listfiles (new Fileonlyfilter ());

string[] ary = new String[files.length];

for (int i = 0; i < files.length; i++) {

Ary[i] = Files[i].getname ();

}

return ary;

}

}


Class Fileonlyfilter implements FileFilter {

Public boolean accept (file file) {

return File.isfile ();

}

}


This article is from the "Li Gang Learning Journey" blog, please make sure to keep this source http://381510688.blog.51cto.com/4623168/1570495

Compression Js-yuicompressor-2.4.jar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.