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
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 >

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
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