Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I write contents of a vector to file?  RSS feed

 
John Lockheart
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method writeFile(Vector information){}. with the following code...


I thought it was simple, but I could use a few tips because this code isn't working. How can I write the vector I pass to the method in a seperate text file?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I don't think you want to write the Vector to the file that way.

It depends on what the Vector contains.

If it contains Strings, iterate through the Vector and write the contents to the file.
 
John Lockheart
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i forgot to mention, it contains objects which have a class hiearchy. two abstract classes with object types underneath them. Although untill an initial file is read, the program won't know the contents of the vector because it isn't even created until the file is read. It could contain 1 object, or 1000.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're going to write the Vector as an object, you need to make sure each object it contains is Serializable and any objects that are part of those class definitions are Serializable.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!