How to create own filetype?
I want to create own filetype to save objects in my app. Basically, I urgently do not need new filetype, but it will be better.
I have class. For example Car. It has constructor (String name, String color, int length, Driver driver). When 开发者_JAVA百科a car is created (its instance), how to save it like a file?
To save object to file you need serialization.
You can choose whatever file extension we like e.g. .car
.
Good serialization tutorial.
I would save it as an XML file with a custom extension. I would them tell my application to read those files as XML. For me, that's the easiest way to ensure consistency. It can also help in the event that your application should need to communicate with another, perhaps on user request.
Basically to 'create' your own file type you define a standard and use your own file extension. There aren't any large hoops to jump through so long as you are consistent.
Though, what you mean by, save your objects, I am unsure.
Additionally look into the Object input and output stream methods. Finally look at this for Serialization of methods in java.
SO. Basically, .ipa files, a file format for IPhone applications, is just a renamed .zip file. from, for example, app.zip to app.ipa is what apple did to .ipa files, they are just a zip. SO. if you rename the .java file extension to .car you have effectively made a new filetype
I have an idea! You could put said car instance in a zip and other files you might want to accompany with said zip and rename that zip. Apple did that with .ipa its just a renamed .zip
精彩评论