저는 Java를 처음 접했습니다. 현재 args []에 주어진 파일 이름을이 FileReader에 전달하려고 시도하지만 컴파일 할 때 지정된 파일을 찾을 수 없다고 말합니다. 파일 이름을 하드 코딩하면 제대로 작동합니다. 어떻게이 일을해야 하죠?Java args 명령 줄 매개 변수 - args의 매개 변수로 filename을 메서드로 전달하려고 시도하지만 작동하지 않습니다.
public class StringSplit
{
public void parseCommands
{
try
{
//not working, why? It works if I do FileReader fr= new FileReader("hi.tpl").
FileReader fr= new FileReader(args);
}
public static void main (String[] args)// args holds the filename to be given to FileReader
{
if (args.length==0)
{
System.out.println("Error: Bad command or filename. Syntax: java [filename.tpl]);
System.exit(0)
}
StringSplit ss= new StringSplit();
ss.parseCommands();
}
}
감사합니다. – Luinithil