#How to write ArrayList to BufferedWriter?

1 messages · Page 1 of 1 (latest)

austere badger
#

I'm using a BufferedWriter and i want to write the content of a ArrayList, how can I do it?

#

How to write ArrayList to BufferedWriter?

gray solstice
#
    _  = try buffered_writer.write(list.items);
    // before end of scope
    try buffered_writer.flush();
gray solstice
#

looks like you have a list of lists. for that you'll need to loop over tracks.items and do this for each one.

austere badger
#

cause write return a usize

gray solstice
#

i agree that writeAll() would be better.

#

i mean it might be better for things like writing to a network stream where partial writes might happen.

austere badger
#

i'm writing to a file

gray solstice
#

not sure if you need it for a buffered writer

#

i would say its better practice to use writeAll(). but i've rarely had issues with write()

austere badger
#

i get a seg fault

#

by doing this

#
for (tracks.items) |track| {
    try flpwriter.writeAll(track.items);
}
gray solstice
#

is there a trace?

austere badger
#

no

#

using debug build mode

gray solstice
#

not sure what might be causing it? any ideas? if not you'd have to show more code for me to help.

austere badger
gray solstice
#

ok. how are you initializing each track?

austere badger
gray solstice
#

ah there it is. you should not call array.deinit()

austere badger
#

thank you!

gray solstice
#

let us know if you run into anything else

austere badger
#

if i seek like this

gray solstice
#

do you want to write to the end of a file? if so, there is a method seekFromEnd(0) i think

austere badger
#

no

#

ok no

#

i'm stupid

#

i don't need this

#

sorry for the waste of time