How do I open a file in the command line arguments? [on hold]

I have to create a program that read files and my professors will test it in the command line.

The argument, he will put to open a file, will be a String. But he said that the file should open with or without the .txt extension.

  • I would like to know what can be the condition for the name of the file?

I was thinking if args[0] does not contain .txt add it, but I have no idea how to do this in code.

I was thinking if args[0] does not contain .txt add it, but I have no idea how to do this in code.

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

0 Comment

NO COMMENTS

LEAVE A REPLY

Captcha image