aspose file tools*
The moose likes I/O and Streams and the fly likes Sending data from an ArrayList to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Sending data from an ArrayList to a file" Watch "Sending data from an ArrayList to a file" New topic
Author

Sending data from an ArrayList to a file

Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
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

Joined: Jul 05, 2011
Posts: 93
    
    1
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

Explicitly close() the FileWriter when you're done with it, preferably in a finally block.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sam Thompson
Ranch Hand

Joined: Jul 05, 2011
Posts: 93
    
    1
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending data from an ArrayList to a file