I wrote a method to read in a txt file and then return the value(s) line by line. However, the value(s) are being returned as such - [Ljava.lang.String;@6f579a30. I would have expected something different. The .txt file I'm reading in has value(s) in the file like this...
A
B
C
D
Any help would be greatly appriciated!
public String[] readFile()
{
//Go fetch the file that I want to read
File file = new File("path-file.txt");
//String[] readLines(file); {
FileReader fileReader = null;
try {
fileReader = new FileReader(file);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(fileReader);
List<String> lines = new ArrayList<String>();
String line = null;
try {
while ((line = bufferedReader.readLine()) != null) {
lines.add(line); }
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
bufferedReader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] answer = lines.toArray(new String[lines.size()]);
System.out.println(answer);
return answer;
}