Reading Binary Data Files

My Unity app requires that I read data stored in a binary file. I’ve been able to read that data in a C# script as follows:

Stream s = new FileStream(“Assets//Resources//pattern1.txt”, FileMode.Open);
BinaryReader br = new BinaryReader(s);
byte[ ] byteArray = br.ReadBytes(4);
…etc…

(Note: the file contains binary and not text data)

The problem I’m having is understanding what happens when I build and run a standalone Windows.exe, the program seems to have trouble locating the pattern1.txt file.

Assets/Resources only exists in Unity and isn’t something you can read in a build. You have to load the file from some external source.

–Eric

or just read it as what it is: A TextAsset instance within unity