Reading integers in from a file

Hi, I think I posted this in the wrong forum before... anyway, my question was:

Hi, I am going to go for the 'reading in from a text file' action as I haven't done this before. So I have been looking at all the examples and am trying the one out below :) My question is that though the structure seems pretty straightforward, what is the action of the 'token' and why doesn't java recognise it as it is used in many different examples that I have seen?

public static int[] getIntegersFromFile(String fileName) throws IOException {

StringWriter writer = new StringWriter();

BufferedReader reader = new BufferedReader(new FileReader(fileName));

List<Integer> list = new ArrayList<Integer>();

for (String line = reader.readLine(); line != null; line = reader.readLine()) {

writer.write(line + " ");

}

StringTokenizer tokens = new StringTokenizer(writertoString());

while (tokens.hasMoreTokens()) {

String str = tokens.nextToken();

try {

list.add(new Integer(str));

} catch (NumberFormatException e) {

System.out.println("Error '" + str + "' is not an integer.");

}

}

int[] array = new int[list.size()];

for( int i = 0; i < array.length; i++){

array = list.get(i);

}

return array;

}

[1346 byte] By [cakea] at [2007-11-26 19:53:20]
# 1
Is this code you have written or a code example you are trying to understand? Also a detailed description of what you are trying to do would be good.
floundera at 2007-7-9 22:45:02 > top of Java-index,Java Essentials,New To Java...
# 2
http://forum.java.sun.com/thread.jspa?threadID=5141994&tstart=0Thanks for double posting and wasting my time butthole!
floundera at 2007-7-9 22:45:02 > top of Java-index,Java Essentials,New To Java...
# 3

> http://forum.java.sun.com/thread.jspa?threadID=5141994

> &tstart=0

>

> Thanks for double posting and wasting my time butthole!

It's worse than that!

@OP: Read Reply #5 in the thread where you initially posted this code:

http://forum.java.sun.com/thread.jspa?threadID=5141967

You didn't need to create a new thread [and worse yet, two new threads!] for this part of the question--you should have waited longer for an answer.

doremifasollatidoa at 2007-7-9 22:45:02 > top of Java-index,Java Essentials,New To Java...