我有一个名为InputTxt
的Java类,它有一个int属性id
。我想写一个shell脚本,创建一个文件与id
作为文件名。
注意:调用此脚本的java函数返回id
以外的内容。
将id
作为参数传递给脚本:
import java.io.*;
class InputTxt {
static int id;
public static void main (String[] args) throws IOException {
id = args.length;
try {
Process p = Runtime.getRuntime().exec(
new String[]{"touch", Integer.toString(id)});
} catch (IOException e) {
throw e;
}
}
}
示例运行:
$ javac InputTxt.java
$ java InputTxt 4 5 6
$ ls
3 InputTxt.class InputTxt.java