Write to a file is easy:
Using writer As New StreamWriter(myOutputFilePath)
writer.WriteLine("Text to write")
End Using
Outputing two separate vales to a file is just a case of doing two WriteLine operations
Reading it back is easy:
Dim lines As String() = File.ReadAllLines(myOutputFilePath)
If lines.Length >= 2 Then
Dim myMP3 As String = lines(0)
Dim myJPG As String = lines(1)
End If
[edit]Just realised: This does not save the data contained in the MP3 and JPG files. Instead, it saves the paths to them. If you need to actually save the file contents, then it is a little (but not too much) more complicated. Very similar set of routines, but you have to be a little more sophisticated. If that is what you want, then ask here. - OriginalGriff[/edit]
"Thank you so much for your answer, but as you said this does not write or save any file,
would you suggest me ho to do it, please?"
There are a huge number of ways to do this.
1) You could use a ZIP as previously suggested.
2) You could create a serializable class, holding holding the contents of an mp3 and a jpg, and let the the framework handle serialization.
3) Do it your self, writing the sizes and file contents to a combined file, and reading them back yourself.
4) Other.
The first option is discussed in other answers.
The second I don't like to use, as it can make future proofing your app difficult: if you change your class, the serialization / deserialization can prove a nightmare.
The third is future proof, but a bit of a pain. Except, there is a middle ground: use a BinaryReader, and a BinaryWriter to make your life easy:
private void butWriteCombined_Click(object sender, EventArgs e)
{
byte[] mp3 = File.ReadAllBytes(@"F:\Temp\(Don't Fear) the Reaper.mp3");
byte[] jpg = File.ReadAllBytes(@"F:\Temp\(Don't Fear) the Reaper.jpg");
using (BinaryWriter bw = new BinaryWriter(File.Open(@"F:\Temp\(Don't Fear) the Reaper.Combined", FileMode.Create)))
{
bw.Write(mp3.Length);
bw.Write(mp3);
bw.Write(jpg.Length);
bw.Write(jpg);
}
}
private void ReadCombined_Click(object sender, EventArgs e)
{
byte[] mp3;
byte[] jpg;
using (BinaryReader br = new BinaryReader(File.Open(@"F:\Temp\(Don't Fear) the Reaper.Combined", FileMode.Open)))
{
int mp3Size = br.ReadInt32();
mp3 = br.ReadBytes(mp3Size);
int jpgSize = br.ReadInt32();
jpg = br.ReadBytes(jpgSize);
}
File.WriteAllBytes(@"F:\Temp\(Don't Fear) the Reaper Extracted.mp3", mp3);
File.WriteAllBytes(@"F:\Temp\(Don't Fear) the Reaper Extracted.jpg", jpg);
}
Obviously, you will want to make the file name user controllable, and probably want to add original file names into teh combined file, but look at MSDN for details of BinaryWriter and BinaryReader - you'll get the idea in no time!