How to open/read/write CSV file once the app is built? (like Resources.Load but whit the built app at Application.dataPath)

Hello there.

As i say in the title, i have this code to load the file in editor:

    if (Application.isEditor)
    {
        Something= Resources.Load("ResourceName") as TextAsset;
    }

But how to load the same info once the game is built, if the csv file is stored at Application.dataPath?? i can’t find the function in google/Unity manual… :frowning:

THAAANKS!

// Code not tested
string path = Application.dataPath + “/Path/To/File.csv”;
Something = new TextAsset( System.IO.File.ReadAllText(path) ) ;

The question is: are you sure your CSV will be located here when the app runs? You may want to consider putting the file in the StreamingAssets if the file already exist in your project, or use Application.persistentDataPath to save & load the file.

I think you can do something like this.

    private string m_path;

    // Start is called before the first frame update
    void Start()
    {

        m_path = Application.persistentDataPath+ "/newcsv.csv";

        if (File.Exists(m_path))
        {
            byte[] m_bytes = File.ReadAllBytes(m_path);

            string s = System.Text.Encoding.UTF8.GetString(m_bytes);

            Debug.Log(s);
        }
    }