title: Java - .csv file as input
body: <p>My program stimulates FCFS scheduling algorithm. It takes a .csv file as input and output the average waiting time. I have trouble with inputting the file. This is the error that i get when i ran the code:</p>
  
  <pre><code>    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
       at main.FCFS.main(FCFS.java:16)
  </code></pre>
  
  <p>What am I doing wrong? I cannot seems to figure it out. Please help. </p>
  
  <pre><code>package main;
  
    //programming FCFS scheduling algorithm
  
  import java.util.Scanner;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.File;
  import java.io.FileInputStream;
  
  public class FCFS {
     public static void main(String[] args) throws FileNotFoundException {
      // To Store Name of the file to be opened
      String file = args[0];
      int i = 0, n;
      double AWT = 0, ATT = 0;
      int AT[] = new int[100];
      int BT[] = new int[100];
      int WT[] = new int[100];
      int TAT[] = new int[100];
      int PID[] = new int[100];
      // To open file in read mode
      FileInputStream fin = null;
  
      // To read input(file name) from standard input stream
      Scanner s = new Scanner(new File("/Users/SLO/ex.csv"));
  
      // To hold each single record obtained from CSV file
      String oneRecord = "";
  
      try {
          // Open the CSV file for reading
          fin = new FileInputStream(file);
  
          // To read from CSV file
          s = new Scanner(fin);
  
          // Loop until all the records in CSV file are read
          while (s.hasNextLine()) {
  
              oneRecord = s.nextLine();
  
              // Split record into fields using comma as separator
              String[] details = oneRecord.split(",");
              PID[i] = Integer.parseInt(details[0]);
              AT[i] = Integer.parseInt(details[1]);
              BT[i] = Integer.parseInt(details[2]);
              System.out.printf("Process Id=%d\tArrival Time=%d\tBurst Time=%d\n", PID[i], AT[i], BT[i]);
              i++;
          }
          WT[0] = 0;
          for (n = 1; n &lt; i; n++) {
              WT[n] = WT[n - 1] + BT[n - 1];
              WT[n] = WT[n] - AT[n];
          }
          for (n = 0; n &lt; i; n++) {
              TAT[n] = WT[n] + BT[n];
              AWT = AWT + WT[n];
              ATT = ATT + TAT[n];
          }
          System.out.println(" PROCESS BT WT TAT ");
          for (n = 0; n &lt; i; n++) {
              System.out.println(" " + PID[n] + " " + BT[n] + " " + WT[n] + " " + TAT[n]);
          }
          System.out.println("Avg waiting time=" + AWT / i);
          System.out.println("Avg waiting time=" + ATT / i);
  
      } catch (FileNotFoundException e) {
          System.out.printf("There is no CSV file with the name %s", file);
      }
  
      finally {
          if (fin != null) {
              try {
                  fin.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
  
   }
  }
  </code></pre>