使用命令行参数将文件传递给程序 [英] Using command-line argument for passing files to a program
本文介绍了使用命令行参数将文件传递给程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何作为命令行参数接收文件?
How can I receive a file as a command-line argument?
推荐答案
只传递文件的路径,程序内部使用Java File类来处理它
Just the path of the file is passed, inside your program use the Java File class to handle it
这将第一个参数作为文件路径:
This takes the first parameter as the file path:
import java.io.File;
public class SomeProgram {
public static void main(String[] args) {
if(args.length > 0) {
File file = new File(args[0]);
// Work with your 'file' object here
}
}
}
这篇关于使用命令行参数将文件传递给程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文