Good day! Jose, i have created both classes en run them in sap netweaver dev studio, also in eclipse - but still the folder "doc" where the document is supposed to be generated, is not there. what could be a reason? thanks
Yes you can, just make sure you read them back in the correct (inverse from writing) order. However, generally people just create one Container object and read-write that. It keeps the code simpler.
I just finished watching Hitchikers Guide to the Galaxy and came straight to this tutorial where you wrote Arthur Dent.. I'm just so confused right now.
Can I use this to show only object of certain attributes? Like if I have several object Task that are due tomorrow while others are due next week, can I retrieve only the ones due tomorrow? Ive been trying to figure out how to store objects and organize them for a whole week now but I am not sure if serializing is the best route.
Great tutorial. How can I read read the values from the txt file and create serializable objects which must be written to a serialized file ???? Please help
I know best practice depends on structure and mission of program but... Is it a strong practice to have a protected/private constructor whos only purpose is to read data from a "save" file for security? Perhaps the only parameter of this is the file itself, if file not found then construct with a public constructor?
Thank you for an awesome explanation, just one question if i may , you mentioned that you have to know the type of the object before you cast it , is it possible to use instanceOf on an object to find out it's type?
Yes. The FileOutputStream constructor takes a second argument that, if true, then it appends to the existing file. That is 'fos = new FileOutputStream(file, true);' will append to 'file'.
If you got an error when running the program then that error message should tell you more about the problem. If you did not get an error then the file (probably) was written. It might be on a different folder than you expect, because of partial path names.
Ugh! I don't know. That means there is a problem with the file data. Maybe you added some extra data to the file? sometimes, if you open the file with some text editors they will add some whitespace to it. Or, maybe you are trying to read more objects than you wrote? I don't know.
I just can save one object per file? Lets say i want to create a person called john after the arthur, can i save it in the same file? If so, when it reads, how java knows if he should read arthur or john?
+Gonçalo Martins Yes, you can write another object after the first, just make sure you append it to the file (not overwrite the existing file). The objects will be stored in the order you wrote them. So, when you go back to read them you will read them in the same order you wrote them.
Whats the point of creating objectinput stream when you're just creating a simple line listing the outputs (p.name , p.age) I thought it would return the saved file by just using (fileName))
Scott Allen So, the point of the video is just to show how to read and write objects to a file. The code itself has no purpose beyond being used as an example in the video. More generally, writing objects to files is very useful when you have an object with many properties (data members). For example, say your object is an instance of MusicLibrary which contains an ArrayList of Songs, each one of which has .title, .artist, etc. You can read/write that whole MusicLibrary to disk with the couple of lines in the video, rather than having to write your own serializer and parser.
The input object and output object are two different objects. The reading and writing diminished the reference pointers of the two objects. That's why we need to cast the input to Person, and if you try arthur.equals(p), it's false, clearly representing there are two objects.
Hello again. Im having a problem. Im working with the bukkit API, and i need to implement this in my project. But before that i created a random project, so i can test it before. I have a command /dog and when i run it, it will create a new dog (my object) with the name Billy and the age 15 and will save it in a file. When i do /mydog it will return the information. The problem is that, if i make /dog and then i reload(enable and disable the plugin with the onEnable and onDisable) the server, it will clean my file. Main - pastebin.com/73PXu91f Dog - pastebin.com/P5DmwQGm PS: Are you portuguese? If so you can reply in portuguese.
+Trevis Gamuchirayi Chipunza This tutorial wasnt really useful for this example. But when you will have your own objects (classes e.g) stored in maps and lists, this is a great way of saving and loading them.
thanks man , good lesson about serializable i'm brazilian java student
and your learning method is the best!
Bro Good job on pinpointing some of the errors im glad i got to see this video it helps me a lot thank you
Good day! Jose, i have created both classes en run them in sap netweaver dev studio, also in eclipse - but still the folder "doc" where the document is supposed to be generated, is not there. what could be a reason? thanks
Great tutorial, this is going to help me on my exam. Thanks!
Yes you can, just make sure you read them back in the correct (inverse from writing) order. However, generally people just create one Container object and read-write that. It keeps the code simpler.
Thank you so much for doing this video! It has been very helpful to me.
I've tried this but when my program is reading the 2nd set of objects that I serialized, it encounters a StreamCorruptedException
I just finished watching Hitchikers Guide to the Galaxy and came straight to this tutorial where you wrote Arthur Dent.. I'm just so confused right now.
Google is watching you...
Thank you for helping me pass my final
Can I use this to show only object of certain attributes? Like if I have several object Task that are due tomorrow while others are due next week, can I retrieve only the ones due tomorrow? Ive been trying to figure out how to store objects and organize them for a whole week now but I am not sure if serializing is the best route.
Great tutorial. How can I read read the values from the txt file and create serializable objects which must be written to a serialized file ???? Please help
Can you serialize more than on object in to a file and read more than one out of a file?
I know best practice depends on structure and mission of program but...
Is it a strong practice to have a protected/private constructor whos only purpose is to read data from a "save" file for security? Perhaps the only parameter of this is the file itself, if file not found then construct with a public constructor?
Is there a way to append the objects when writing to the file ?
Thank you for an awesome explanation, just one question if i may , you mentioned that you have to know the type of the object before you cast it , is it possible to use instanceOf on an object to find out it's type?
Yes. The FileOutputStream constructor takes a second argument that, if true, then it appends to the existing file.
That is 'fos = new FileOutputStream(file, true);' will append to 'file'.
Sir, how can I read multiple objects if I have written more than 1 one object in that file.?
Sos el Jose! muchas gracias bombon!
Good video, thanks !
Hi, when you sysout, eclipse automatically fills up the rest for u.. System.out.println()
How did you get this done? Thanks
See my "Eclipse tips and tricks" video Eclipse Tips and Tricks for Beginners Tutorial
you just have to type syso and press ctrl + space..
Thank you Alex
Hi Mr. Jose, when you type 'sysout', eclipse automatically fills up the rest for u.. System.out.println()
How did you get this done? Thanks
type syso then press ctrl+space
Thanks so much for the tutorial!
Thanks for this - great tute :)
How do i serialize and deserialize a JSpinner? For a GUI?
Very helpful. Thank you!
If you got an error when running the program then that error message should tell you more about the problem.
If you did not get an error then the file (probably) was written. It might be on a different folder than you expect, because of partial path names.
Thanks, very nice explanation
Great....Tks a Lot Jose.....Muchas Gracias
helped a lot bro
És grande, Zé
Ugh! I don't know. That means there is a problem with the file data. Maybe you added some extra data to the file? sometimes, if you open the file with some text editors they will add some whitespace to it. Or, maybe you are trying to read more objects than you wrote? I don't know.
this was very helpful. thank you.
I just can save one object per file? Lets say i want to create a person called john after the arthur, can i save it in the same file? If so, when it reads, how java knows if he should read arthur or john?
+Gonçalo Martins Yes, you can write another object after the first, just make sure you append it to the file (not overwrite the existing file). The objects will be stored in the order you wrote them. So, when you go back to read them you will read them in the same order you wrote them.
Jose Vidal Thank you, it worked :)
You just call it twice.
The first is for the first object, the second for the second etc...
good question and good answers
It doesnt creates an folder "docs" with the data.bin in it.
It's just creating the data.bin and Eclipse doesn't show me the file. Why?
+misterdubsteppa Refresh your project. The folder docs it was already there.
Whats the point of creating objectinput stream when you're just creating a simple line listing the outputs (p.name , p.age) I thought it would return the saved file by just using (fileName))
Scott Allen So, the point of the video is just to show how to read and write objects to a file. The code itself has no purpose beyond being used as an example in the video. More generally, writing objects to files is very useful when you have an object with many properties (data members). For example, say your object is an instance of MusicLibrary which contains an ArrayList of Songs, each one of which has .title, .artist, etc. You can read/write that whole MusicLibrary to disk with the couple of lines in the video, rather than having to write your own serializer and parser.
hay here you make a data.txt file instead of data.bin and write in character not in binary?????
very helpful, thanks
can you save linked lists?
billyblackburn87 Yes, any Serializable object can be saved.
Jose Vidal wow thankyou for the quick reply
around 9:00 mins, adding 'transient' keyword in front of a variable makes it non-serializable.
The title of the Video says "Objects" but you are only doing 1 object.
The input object and output object are two different objects. The reading and writing diminished the reference pointers of the two objects. That's why we need to cast the input to Person, and if you try arthur.equals(p), it's false, clearly representing there are two objects.
thank you my man
nice explaination but do it for multiple objects
IntelliJ wasn't adding the ClassNotFoundException for me so watch out for that took me longer than I'm proud to admit to catch that.
Thanks man, helped alot. :)
u can juz make it into a txt file and use scanner and fileWriter
Thanx a lot really perfect (Y)
thank you sir.
Thanks !
Hello again.
Im having a problem.
Im working with the bukkit API, and i need to implement this in my project. But before that i created a random project, so i can test it before. I have a command /dog and when i run it, it will create a new dog (my object) with the name Billy and the age 15 and will save it in a file. When i do /mydog it will return the information. The problem is that, if i make /dog and then i reload(enable and disable the plugin with the onEnable and onDisable) the server, it will clean my file.
Main - pastebin.com/73PXu91f
Dog - pastebin.com/P5DmwQGm
PS: Are you portuguese? If so you can reply in portuguese.
+Gonçalo Martins Nevermind, bukkit api provides a way of do it ;) I solved it.
thanks!
harvey dent?
thanks!!
thanks
I still don't get all
this
+Trevis Gamuchirayi Chipunza This tutorial wasnt really useful for this example. But when you will have your own objects (classes e.g) stored in maps and lists, this is a great way of saving and loading them.
watching this video Im feeling like in 2006
I wish that this tutorial was in spanish =(
can you save linked lists?
Thx