简体   繁体   English

通过命令行参数读取文件名

[英]reading filename through command line argument

I came across the following code in a book recently. 我最近在一本书中遇到了以下代码。 It says that we can reference a file for instance that we want to read by writing a command line like the first line below. 它说我们可以通过编写命令行(例如下面的第一行)来引用要读取的实例文件。 However it is throwing an error with this line. 但是,它在此行上引发了错误。 Can someone please advise as I have never come across this before? 有人可以指教一下,因为我以前从未遇到过这种情况吗?

Thanks 谢谢

java ShowFile c:/Users/Bosra/Desktop/Sample.txt
import java.io.*;


public class ShowFile
{
public static void main(String args[])
{
    int i;
    FileInputStream fin;

    //first confirm that a filename has been specified
    if(args.length!=1)
    {
        System.out.println("Usage:ShowFile Filename");
        return;
    }
}
}

第一行是您在编译文件后应在命令行中键入的内容-它不属于文件本身。

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

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