如何讓此程序在命令行的「lab13.txt」中讀取?我一直試圖弄清楚這個問題一個多小時,沒有任何工作。如何使程序使用您在命令行中指定名稱的文件
提示是「編寫一個程序,確定並顯示在命令行中指定名稱的文件中的行數。使用lab13.txt測試您的程序。」
import java.util.Scanner;
import java.io.*;
class homework
{
public static void main(String[] args) throws IOException
{
Scanner inFile= new Scanner(new File("lab13.txt"));
int count=0;
String s;
while (inFile.hasNextLine())
{
s = inFile.nextLine();
count++;
}
System.out.println(count + " Lines in lab13.txt");
inFile.close();
}
}