package algorithms.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class InputUtil {
  private static final String INPUT = "input_files/";

  public static String[] readContents(String fileName) throws FileNotFoundException {
    StringBuffer buffer = new StringBuffer();
    StringBuilder fileBuilder = new StringBuilder(INPUT);

    File inputFile = new File(fileBuilder.append(fileName).toString());
    FileReader fileReader = new FileReader(inputFile);
    Scanner scanner = new Scanner(fileReader);

    while (scanner.hasNextLine()) {
      String line = scanner.nextLine().trim();
      if (line != null && !line.isEmpty()) {
        buffer.append(line).append("\n");
      }
    }
    scanner.close();

    return buffer.toString().split("\n");
  }
}

@@ -126,252 +126,171 @@
 til.
-Scanner;%0A%0Apublic class InputUtil %7B%0A  private static final String INPUT = %22input_files/%22;%0A%0A  public static String%5B%5D readContents(String fileName) throws FileNotFoundException %7B%0A    StringBuffer buffer = new StringBuffer();%0A    StringBuil
+ArrayList;%0Aimport java.util.List;%0Aimport java.util.Scanner;%0A%0Apublic class InputUtil %7B%0A%0A  public static String%5B%5D readContents(String filePath) %7B%0A    FileRea
 der file
 Buil
@@ -289,131 +289,73 @@
 file
-Buil
+Rea
 der = n
-ew StringBuilder(INPUT);%0A%0A    File inputFile = new File(fileBuilder.append(fileName).toString());%0A    FileReader
+ull;%0A    List%3CString%3E inputList = null;%0A    try %7B%0A     
  fil
@@ -383,20 +383,31 @@
 der(
-inputFile
+new File(filePath)
 );%0A
+  
     
@@ -449,17 +449,62 @@
 eader);%0A
-%0A
+      inputList = new ArrayList%3CString%3E();%0A%0A  
     whil
@@ -537,16 +537,18 @@
 %7B%0A      
+ 
+ 
 String l
@@ -586,16 +586,18 @@
 ;%0A      
+  
 if (line
@@ -639,42 +639,33 @@
     
+  
-buffer.append(line).append(%22%5Cn%22);%0A
+inputList.add(line);%0A  
     
@@ -668,26 +668,30 @@
       %7D%0A    
-%7D%0A
+  %7D%0A  
     scanner.
@@ -695,25 +695,26 @@
 er.close();%0A
-%0A
+  
     return b
@@ -716,37 +716,192 @@
 urn 
-buffer.toString().split(%22%5Cn%22)
+(String%5B%5D) inputList.toArray(new String%5BinputList.size()%5D);%0A    %7D catch (FileNotFoundException e) %7B%0A      System.out.println(%22File Not Found %22 + e.getMessage());%0A    %7D%0A%0A    return null
 ;%0A  

Refactor InputUtil to read contents, TODO: Move to a common class