I’m fairly new to Java. Currently trying to have the filename given in args[] passed to this FileReader but when I compile it says it can’t find the specified file. If I hardcode the filename it works fine. How’s this supposed to work?
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();
}
}
Your args parameter is not visible to parseCommands.
Plus args is an array. You probably want to send the first element in that array to parseCommands.