在bash中读取Java变量值



我有一个名为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

最新更新