本文介绍了使用命令行参数将文件传递给程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何作为命令行参数接收文件?
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 } } }更多推荐
使用命令行参数将文件传递给程序
发布评论