我使用以下代码使用YUI Compressor压缩CSS文件,但CSS文件不会被压缩,它保持不变。任何想法为什么?
final InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(fileCss), "UTF-8");
final CssCompressor cssCompressor = new CssCompressor(inputStreamReader);
inputStreamReader.close();
final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(fileCss), "UTF-8");
final Integer cssParamLineBreak = -1;
cssCompressor.compress(outputStreamWriter, cssParamLineBreak);
outputStreamWriter.close();
fileCss是来自循环槽FileUtils.listFiles
的YUICompressor-2.4.8
LE:他们确实在构造函数中读取文件。见https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/CssCompressor.java#L25
我编写了基于https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/YUICompressor.java#L20的代码,当您从命令行调用jar时,该代码可以正常工作。它们与初始化压缩器后关闭输入流的方式相同。
如果输入文件与输出文件相同,则从命令行开始工作。