christopher_bo...@yahoo.co.uk schrieb:
Hi all.
i am trying to read data from a text file and add it into an Array so
that I can read the data from the Array back in again. I haven't got a
clue how to create an Array.
Can someone help me.
Any help in this matter would be appreciated.
Thanks for any help.
What do you mean saying "read data from a text file and add it into an
Array"? Do you want to put the separate lines as Strings into a String[]?
If you want it like that, you can use a LineNumberReader:
try {
List<String> lines = new LinkedList<String>();
FileReader fileReader = new FileReader("filename");
LineNumberReader reader = new LineNumberReader(fileReader);
while (reader.ready()) {
lines.add(reader.readLine());
}} catch (IOException e) {
System.out.println(e);
}
As said, you can then convert the List to an array using lines.toArray().
intensive research. thank you!