bufferReader

Hi, I am reading information from a csv file to transfer into a database, i know how to read data such as

1.1,1.2,1.3,1.4,1.6 by using bufferReader to read the line and the split the line using a string tokenizer , and then storing the tokens in an array.

however i cant work out how to do it when the data is presented in multiple lines e.g.

1.1,

1.2,

1.3,

1.4,

please help

thanks in advance

[447 byte] By [liam_mcmorrowa] at [2007-11-27 1:19:51]
# 1
Read a line, add the value to a List, read next line, add value to List, and so on.Kaj
kajbja at 2007-7-11 23:56:27 > top of Java-index,Java Essentials,New To Java...
# 2

what's the problem ?

process them as usually, look :

public static void main(String[] args) {

String [] a= {"1.0,", "1.1,", "1.2,"};

String [] array;

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

array = a[i].split("\\,");

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

System.out.println(array[j]);

}

}

}

BTW, use String.split(String regexp) instead of stringtockenizer.

hth

java_2006a at 2007-7-11 23:56:27 > top of Java-index,Java Essentials,New To Java...
# 3
i could only find a readline() method for the bufferReader how do i move on to the next line
liam_mcmorrowa at 2007-7-11 23:56:27 > top of Java-index,Java Essentials,New To Java...
# 4

BufferedReader br = ...;

String line = null;

while((line=br.readLine())!=null){

//process the current line

}

example:

try {

BufferedReader in = new BufferedReader(new FileReader("infilename"));

String str;

while ((str = in.readLine()) != null) {

process(str);

}

in.close();

} catch (IOException e) {

}

hth

Message was edited by:

java_2006

java_2006a at 2007-7-11 23:56:27 > top of Java-index,Java Essentials,New To Java...
# 5
> i could only find a readline() method for the> bufferReader how do i move on to the next lineThat's done automatically.Kaj
kajbja at 2007-7-11 23:56:27 > top of Java-index,Java Essentials,New To Java...
# 6
thats pretty much what my code is at the mo, but it only reads the first line, how do i get he bufferReader to read the next line of data
liam_mcmorrowa at 2007-7-11 23:56:27 > top of Java-index,Java Essentials,New To Java...
# 7
oh, so if i repeatedly call the readline method then it will read the next line each time its called, is tis right?
liam_mcmorrowa at 2007-7-11 23:56:27 > top of Java-index,Java Essentials,New To Java...
# 8
> oh, so if i repeatedly call the readline method then> it will read the next line each time its called, is> tis right?Correct.
kajbja at 2007-7-11 23:56:27 > top of Java-index,Java Essentials,New To Java...
# 9
thanks
liam_mcmorrowa at 2007-7-11 23:56:27 > top of Java-index,Java Essentials,New To Java...