简体   繁体   English

使用unix在Java中运行文本文件

[英]run text file throught java using unix

i want it to compile my java program given a text file without having to hard code the file name into my program. 我希望它编译给定文本文件的Java程序,而不必将文件名硬编码到我的程序中。 I just don't know how the command line for it. 我只是不知道如何使用命令行。

for example: 例如:

javac Main1.java

java Main1 myText.txt

main methods' args parameter is there for you. main方法的args参数在那里。

public static void main(String[] args) {
    // `args` contains command line arguments.
    String filename = args[0];
    ...
}

See Command line arguments . 请参阅命令行参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM