-2

I am new in Java and I want program to get as argument a different sign. For example: java program # And in program I convert string to char like this: char c = args[0].charAt(0); or like this: char [] c = args[0].toCharArray(); But when I put *, it doesn't work. I print and get D or even name of file.

kelp_sk
  • 1
  • 2

1 Answers1

0

When you use * character in the command line, it becomes expanded - that's why you get a filename/list of filenames.

You may try escaping asterisk:

  • using backslash \ : java program \*
  • using double quotes " (which should also be escaped): java program \"*\" However, in both cases you're likely to get the asterisk along with the escape character.

Other solutions to similar issue are shown here.

Nowhere Man
  • 18,291
  • 9
  • 17
  • 38