Beginner needs help with file I/O...
Lets say I have a data file delimited with semicolons like this:
item1description;12.50;18.99;10
item2description;9.25;12.00;35
item3description;19.60;25.75;4
I am wanting to be able to read each line and take from it, for example, the third field. What technique should I try using? I can use BufferedReader and the readLine()....I try to use loops nested in a for loop to search each character for the ';' but really dont know where to go from there. I can print the entire file out, but what should I be doing to get only certain fields? Can someone out there point me in a general direction (just give me advice...still want to try and figure this out myself....part of the learning process) ? If I didn't provide enough information for anyone to help me, just let me know and thanks in advance...
:)
Maybe something like this?
Well, I can give you an example of what I did...without knowing exactly what you need, it is hard to say. Keep in mind that you should have a "data" class with get and set methods. Once you set up each object in the array, you can use the accessor/mutator methods like this:
Code:
public double getWholeAmt() {
double sum = 0.0;
double total = 0.0;
int quant = 0;
for (int i = 0; i < item.length; i++) {
if (item[i] == null)
break;
total = total + item[i].getWholesale();
quant = quant + item[i].getQuantity();
sum = sum + total * quant;
total = 0.0;
quant = 0;
}
return sum;
}
item is the name of my array. I have stretched out the code to try and illustrate what I am doing. This is the first time I have tried to help anyone and I am a beginner. If it looks like I am stumbling too, please let me know.