- Home /
What files can .NET I/O read?
I've been testing out the .NET I/O class, and I've been able to read a txt file and xml file through unity, but what's the limit as to what I can read? Does "character encoding" have something to do with it? And lastly, can I read files other than text files? Such as a .png?
The WWW class can read in texture files.
Is the WWW class strictly on online thing? I should probably add that I'm working on a windows standalone.
System.IO doesn't care what the extension of a file is: xml, png, jpg, txt... it's all just bytes.
@tanoshimi So, could I load a .png sprite through System.IO for use by Unity?
Yes you can, Texture2D have a function called LoadImage that as it says load an image from a byte array. EG usage:
static public byte[] ReadImageBytes (string fPath) {
byte[] b = System.IO.File.ReadAllBytes(fPath);
return b;
}
fPath beign the path to the file or alternatively you can pass a TextAsset and retrieve the .text from it.
Answer by Jeff-Kesselman · Jul 15, 2014 at 04:38 PM
You can open and load any data file you have permissions to with System.IO.
But System.IO for the most part knows nothing about format, so what you will get is the raw bytes. If you want to, say, load and use a PNG, you need png loader code that will read those bytes and create an image from them.
Your answer
![](https://koobas.hobune.stream/wayback/20220613154131im_/https://answers.unity.com/themes/thub/images/avi.jpg)