• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Sending data from an ArrayList to a file  RSS feed

 
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone

I am working on a project regarding generating data from a Monte Carlo experiment. As of right now everything is working fine... except for one thing. What I need the program to do is to write or save the data values generated to a simple csv or text file. The data is stored in an ArrayList since the amount of generated values will be determined by the user (or in this case, be determined by the number of repeated trials the experiment is executed).

So far, though, every time I compile and run the code, the actual file is saved but NOTHING is in it! It is nothing more but an empty text file. Here is my code below. I know it looks like a lot but to help simplify the problem I have bolded and italicized the problematic code for you.



Again, as I said before, I know it looks like a lot but I'm having difficulty with this one part. Other than that it would work as expected.

Thanks everyone!
Hope to hear from you soon.

S.T.
 
Sam Thompson
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok... so much for bolding and italicizing... :/

Where you want to look is where the method savaDataOnDisk() is at, on line 236 ff. Then there is one more line of code in the main(), referring to the method, on line 341.

Again, thanks everyone. Hope this isn't too much. I just posted everything so that way if and when you decide to compile it yourself, you don't have any problems doing so.

S.T.
 
Sheriff
Posts: 21745
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Explicitly close() the FileWriter when you're done with it, preferably in a finally block.
 
Sam Thompson
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob...

It's spitting something out now thank goodness.

However, I have two questions for you- and other people can answer this too.

So far it's spitting out just one value. I want it to print or write in the file ALL the values from storeprobs.get(0) to storeprobs.get(cycle).

Also, what do you do exactly when you want it to print on different consecutive lines. I've tried /n but it doesn't work.

Thanks again.

S.T.
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!