• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Still can't write vector to file...?

 
John Lockheart
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write a static method in my program called writeFile(). I have a class hierarchy in place which has an abstract class Threat, classes that extend it, an abstract class Malware which also extends Threat (and classes that extend Malware). They are all diffrent threats that I create in the program. I make the Class at the top of the hiearchy (Threat) implement Serializable because every other class extends it. Then i create a vector which stores all these threat objects I create. I thought it was possible to write the entire vector to a txt file with one command? Don't worry, i have try and catch blocks in place, and I do the same for closing the file. How do I write a vector with objects to a txt file then?

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you run it? What is the error?
 
John Lockheart
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no error, it compiles...although i do get a warning, "java uses unchecked or unsafe operations"...but I had that before. I think it's because I have a factory method. I use it to create objects according to input by the user. Anyways, the file I try to write to isn't even created after i run the program, and If i create a blank txt file and name it accordingly, nothing gets written to it. I'm stumped.
 
John Lockheart
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nevermind...i'm just a bit slow. I didn't realise that I commented out the call to the static method which passed the vector as a parameter. I was making some mods to the program and completely forgot i did that. It wasn't writing aything to file because I didn't pass the method the vector. OOPS!! got it working now, sorry to waste your time.
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Lockheart:
There is no error, it compiles...although i do get a warning, "java uses unchecked or unsafe operations"...but I had that before. I think it's because I have a factory method. I use it to create objects according to input by the user. Anyways, the file I try to write to isn't even created after i run the program, and If i create a blank txt file and name it accordingly, nothing gets written to it. I'm stumped.


Works for me... created test vector, with a bunch of strings, wrote the vector out to the object output stream, closed the file, open the file for reading, read the vector back via object input stream, printed it out to confirm it. The file is definitely created, and the data is stored correctly, as I was able to read it back in.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic