Create image-file from resources image


I am working on an leveleditor for standalone, where each level can have a picture.
An example level is created, if the editor does not contain any levels, consisting of a txt file for the coordinates of the elements and the image from the resources-folder:

void CreateExample(){
  if(!Directory.Exists(Application.dataPath+"/Resources/Levels/") || 
		string exampleLevel = "0:Corridore:(-1.0, 0.0, -1.0):(0.0, 0.0, 0.0)";
		Texture2D exampleImage = Resources.Load("Levels/Example.jpg") as Texture2D;
		byte[] bytes = exampleImage.EncodeToJPG(100);
		BinaryWriter binary = new BinaryWriter(bytes);
		File fileImage = File.Open(Application.dataPath+"/Resources/Levels/Example.jpg", FileMode.Create);
		PlayerPrefs.SetString("Levelname", "Example");	

But there are some big errors when it’s trying to write the image-file.

error CS0723: `fileImage’: cannot declare variables of static types

Like File.WriteAllText you could use File.WriteAllBytes:

byte[] bytes = exampleImage.EncodeToJPG(100);
File.WriteAllBytes(Application.dataPath+"/Resources/Levels/Example.jpg", bytes);