-1

I'm getting an ArrayIndexOutOfBoundsException: 0 error.

Here is a small snippet:

public static void main(String[] args){
try{
    Fileread = new BufferedReader(new FileReader(args[0]));
}
catch(FileNotFoundException e){
    System.out.println("Error reading in file");
    System.exit(1);
}

I'm reading in a text file that is 50+ lines. I am somewhat new to just using args[] array to read in initial input. So forgive me for my lack of knowledge.

samrap
  • 5,595
  • 5
  • 31
  • 56

1 Answers1

0

Assuming you do not get a FileNotFoundException, it is safe to say that your exception is related to your arguments i.e. arg[0]...

How are you running your java class? to be able to run it properly you need to run it like this. . i.e. if class name is Memory and filename is Memory.java then you compile it using javac Memory.java and you run it like this..

java Memory C:\abc.txt
Waqas Memon
  • 1,247
  • 9
  • 22