【问题标题】:How do I open a file in the command line arguments? [closed]如何在命令行参数中打开文件? [关闭]
【发布时间】:2018-03-20 04:18:08
【问题描述】:

我必须创建一个读取文件的程序,我的教授将在命令行中对其进行测试。

他将打开文件的参数将是String。但他说该文件应该使用或不使用.txt 扩展名打开。

  • 我想知道文件名的条件是什么?

我在想如果args[0] 不包含.txt 添加它,但我不知道如何在代码中执行此操作。

【问题讨论】:

  • 请展示您的尝试。
  • 你的问题描述不是很清楚。你到底想达到什么目的?你的代码有什么要求?

标签: java command-line-arguments


【解决方案1】:

我在想如果 args[0] 不包含 .txt 添加它,但我没有 想法如何在代码中做到这一点。

if (args[0].endsWith(".txt")) {
  openFile(args[0]);
} else {
  openFile(args[0] + ".txt");
}

【讨论】:

    猜你喜欢
    • 2012-01-06
    • 2013-05-18
    • 1970-01-01
    • 2012-03-15
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    相关资源
    最近更新 更多