• Post Reply Bookmark Topic Watch Topic
  • New Topic

IO close line  RSS feed

 
Hassan Massalha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
how i can devoid the use of close line? in other words, my program have a lot of connections between classes and i want to collect data for one parameter, but after each time the program write in a file he close it... and finally the generated file have the last value..

thanks
 
Noam Ingalls
Ranch Hand
Posts: 60
Chrome Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there's quite enough information here: What are you using for input and output from and to files? FileReader and BufferedReader? FileInputStream? If you could kindly attach the relevant bit of your code it might help us here understand what you're trying to get at. It's not very clear what exactly are you having trouble with.

If you're trying to just close out a method that does all the reading and/or writing, then you probably want to do something like method.close(). I think this page might be relevant to your question.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either
1. Open your Writer/OutputStream in one place and then pass a reference to it to all the other classes that use it. If you do this you will need to make sure that it is flushed regularly and eventually closed.

2. Open your Writer/OutputStream in all the separate places as you do now but open it in append mode rather than create mode. I'm not sure if this is possible with all Writers/OutputStreams. If it isn't with the one you are using, you will have to change to a different one.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!