fileset java_Java FileSet.iterator方法代码示例

import org.apache.tools.ant.types.FileSet; //导入方法依赖的package包/类

public void execute() throws BuildException {

if (outputDir == null) {

throw new BuildException ("no output directory declared!");

}

if (!outputDir.exists()) {

throw new BuildException ("Output directory doesn't exist:" + outputDir);

}

String javaHome = System.getProperty("java.home");

String javaBin = javaHome + File.separator + "bin" + File.separator + "java";

String classpath = System.getProperty("java.class.path");

// add on our own paths

String allPaths = "";

for (Path p : paths) {

classpath += ":" + p.toString();

}

for (FileSet fs : filesets) {

for (Iterator it = fs.iterator(); it.hasNext(); ) {

FileResource res = (FileResource) it.next();

// convert name into CLASS (trim .java and replace slashes)

String name = res.getName();

name = name.substring (0, name.length()-5);

String className = name.replace('/', '.');

try {

ProcessBuilder builder = new ProcessBuilder(javaBin, "-cp", classpath, className);

Process process = builder.start();

// process output

InputStream is = process.getInputStream();

InputStreamReader isr = new InputStreamReader(is);

BufferedReader br = new BufferedReader (isr);

File outFile = new File (outputDir, className + ".output");

PrintStream ps = new PrintStream (outFile);

// generic start/stop info for each output file.

Date d = new Date();

ps.println ("Start:" + d.getTime() + " [" + d + "]");

String s;

int nb = 0;

while ((s = br.readLine()) != null) {

nb += s.length();

ps.println(s);

}

// generic end

d = new Date();

ps.println ("End:" + d.getTime() + " [" + d + "]");

ps.close();

int ev = process.exitValue();

System.out.println (className + " [" + nb + " bytes output, exit code:" + ev + "]");

} catch (Exception e) {

throw new BuildException ("unable to process class " + className + ": " + e.getMessage());

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值