Philip Grove wrote:Reading multiple files regardless of format is perfectly doable, you just have to make sure not to overwrite "old" data when reading new files.
Using StringTokenizer is strongly discouraged, it's a legacy class retained for compatability reasons. Look into the split() methods of String or the java.util.regex package. While regular expressions might be difficult at first, and more so in Java as they don't use the standard POSIX syntax, it's a very powerful tool.
If you want a object doing the splitting, then look at the Scanner class of the java.util package, it does support having a String as a source.
Hello,
Thanks for the reply. I have the following code to read the CSV file. Can you explain what you are saying with some code sample? Do you want loop through all files?
My delimiter in this case is space " ".
String strFile = "C:/Users/Data.csv";
BufferedReader br = new BufferedReader(new FileReader(strFile));
String strLine = "";
StringTokenizer st = null;
int lineNumber = 0;
int numbers[][] = new int[120][2];
//pretend you're looping through lines in a file here
while((strLine = br.readLine()) != null)
{
lineNumber++;
//break space separated line using " "
st = new StringTokenizer(strLine, " ");
while(st.hasMoreTokens())
{
//display echo values
int data1 = Integer.parseInt(st.nextToken());
numbers[lineNumber][0] = data1;
int data2 = Integer.parseInt(st.nextToken());
numbers[lineNumber][1] = data2;
System.out.println("Data1=" + data1 + " Data2=" + data2);
}
}