• Post Reply Bookmark Topic Watch Topic
  • New Topic

Manipulating data from BufferedReader  RSS feed

 
Vance Rodriguez
Greenhorn
Posts: 5
Eclipse IDE Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello .

I've got a .csv file with some text and numeric data.
I've used BufferedReader to successfully print the data to the console.
Now I need to perform mathematical operations on the numerical data.
How do I access the data from the BufferedReader in my calculation methods?

This is what my BufferedReader looks like:

What I would like to be able to do is create some loops to calculate totals for some of the elements, but I'm not sure how to access the data from other methods (and potentially classes?).

First post (of many hopefully) on the forum!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vance,
Welcome to CodeRanch!

You could store the data in variables and pass those variables to other methods:



Or you could read the file from different places where you need the data. (Which is less efficient.)

Or you could read the whole file into an Arraylist and pass that around in your program.
 
Vance Rodriguez
Greenhorn
Posts: 5
Eclipse IDE Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,

Thanks for the great response!

I've done some more reading and I think an array is the best way of storing the data, my only concern is that there is more than one data type. I believe I should be able to declare an array of type String and then later cast to int/double in the calculations. Would that work? The other option is to lose the String data in the .csv and worry about reproducing that later.

This is what the .csv looks like:

itemA,345,587,173,225
itemB,554,328,479,438
itemC,805,189,443,226
etc.

I'm having trouble getting the data out of the try, I can only seem to access them locally. Is there a way to get the data using an accessor or similar?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!