Reputation: 2345
Is it possible to convert a file to a byte array and save it at a later time while keeping all of its properties (name, type, etc)?
I'm reading email attachments and saving the bytes for future use. Issue with this is I don't know how to determine what file extension I need to use when saving the file.
If not what are the alternatives?
Upvotes: 0
Views: 476
Reputation: 33738
name, attributes, timestamps, etc are all meta data of the file and not part of the file contents.. so you need a container format.. You could use XML, or MIME messages, or any encapsulation scheme you desire.
Upvotes: 2
Reputation: 564323
You will need to store the properties, as well. If the byte array is merely the contents of the file, the properties would be lost.
You could, easily enough, just store all of the above information together. A single serializable class with the byte[]
data and all relevant properties could be serialized into a byte array and used, for example.
Upvotes: 1
Reputation: 887195
You need to store the filename (a string) along with its contents.
Upvotes: 1