-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.

3
  • 4
    stackoverflow.com/questions/1055318/… Commented Sep 19, 2016 at 21:47
  • do you pass your path to your file as the first program argument? Commented Sep 19, 2016 at 21:48
  • I am doing file.txt || java Memory: I am assuming that is the correct way? Commented Sep 19, 2016 at 21:51

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.