Campbell Ritchie wrote:
Yes, but what is the problem? If you want to change that format, alter the toString() method in the contact class.Ruben Ochoa wrote:. . . Right now i did the output will be only in one line: somename somesurname sometelephone . . .
Don't close your buffered writer; use try with resources which is a more reliable way to close a resource.
Knute Snortum wrote:It's good to remember that saying ItDoesntWorkIsUseless (that's a link). Tell us what happened in detail. We can't help it we don't know what's going on.
Knute Snortum wrote:...but weren't we talking about fixing this code?
Then you could do this with a "for each" loop:
That would give you a file with each field on a separate line. That may not be what you want.
While I write this, I see you have posted how you want the data to be saved. You probably don't want to use the method above. Do you have a Contact class? If so, use a list of contacts, List<Contact>, then use a loop like this:
If you write a toString() method correctly, this format will post to the text file.
Carey Brown wrote:What format do you want the line in? How are you going to deal with multiple contacts if you have only one text field for each contact field?
Knute Snortum wrote:Have you tried a "for each" loop? They work well with Lists:
Carey Brown wrote:
You need to be clearer when responding. Do you get "[]" or do you get "somename"?Ruben Ochoa wrote:Indeed. The output is [ ],[ ].[ ] 3 times, filled by names. What loop i must use? While(true)? I tried
You are filling your array with three pieces of data. When you are printing the data you will get a single line of three pieces of data separated with commas. If you want multiple name entries you'll have to fill your list outside of this write method. You don't need any loop to write the three pieces of data. You will need a loop if you fill in the list outside of your method.