[Solved]copy data from resources to persistent data path

I want to copy files(images) from Resources to Application.persistentDataPath. Here’s the code:

private void SaveFile (string fileName)
{
	Texture2D texture = Resources.Load (System.IO.Path.GetFileNameWithoutExtension (fileName)) as Texture2D;
	byte[] bytes = ?//i need to get byte array from texture
	System.IO.File.WriteAllBytes (Application.persistentDataPath + folder, bytes);
}

The question is: can we get byte array of files in Resources folder? Or can we get byte information from textures?

UPD: if you want to copy file to persistent data path, you may use TextAssets(notice, your file has to have “bytes” extension on yr file to copy binary data).

You can use texture.EncodeToPNG

Hi,

Here i followed like this and working perfect.

First i placed a ImageToUpload.png file in resources folder and renamed its extension .png to .bytes

Then called the below lines in void Start() to copy the image in persistentDataPath.

  void Start(){
    TextAsset imageTextAsset;
    imageTextAsset = Resources.Load (System.IO.Path.GetFileNameWithoutExtension ("ImageToUpload")) as TextAsset;
    File.WriteAllBytes(Application.persistentDataPath + "/ImageToUpload.png", imageTextAsset.bytes);
    }