0

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?

4
  • 1
    As long as you keep the information somewhere... Commented Nov 9, 2011 at 18:34
  • What 'properties' are you concerned about? Commented Nov 9, 2011 at 19:30
  • It was the metadata. Instead I save the file on disk then simply keep the file name. Commented Nov 10, 2011 at 12:34
  • You don't get a lot of meta-data with an attachment. Commented Nov 10, 2011 at 22:26

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to store the filename (a string) along with its contents.

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.