I want to create a method in Java which reads data from a txt file and returns an array. I created the first version of this method - I can say that it works but I have a feeling that the shape of this method is not effective and there is a way to do it much more faster and better... can I ask you to have a look and let me know what can be done better?
thank you very much in advance for your valuable help
public static String[] reader(File file) throws IOException {
String array[] = null;
StringBuilder stringBuilder = new StringBuilder();
String data;
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
int i = 0;
while ((data = reader.readLine()) != null) {
System.out.println("I've just read a line number" + (i + 1));
i++;
stringBuilder.append(data + "/");
}
if (stringBuilder != null) {
data = stringBuilder.toString();
array = data.split("/");
}
return array;
}
}