- Home /
File.ReadAllText vs Resources.Load Character Encoding
I posted a similar question earlier but deleted it because I was wrong about the problem.
I'm trying to swap this code:
string contents = System.IO.File.ReadAllText("filename", Encoding.Unicode);
With this code (so I can put it on a web player):
TextAsset temp = (TextAsset)Resources.Load("filename", typeof(TextAsset));
string contents = Encoding.Unicode.GetString(temp.bytes);
I've also just tried getting the plain string directly using temp.string, but neither one produces the same encoding of the results as my old code did. The text file itself has a lot of weird characters, like NUL, ACK, and Chinese symbols, and I don't quite understand how the code processes them (I didn't write it), but I can tell it's being interpreted wrong because the new code gives me an invalid input error when I try to pass the result to the next method, while the old code works just fine.
Anyone know what is different about those two statements?
I haven't rejected this question. But please immediately re-edit it and format the code.
Answer by Opde · Jun 10, 2016 at 11:36 AM
The WebPlayer does not support File.ReadAllText
Is it because it can't find the file? What if you use Application.dataPath
?
Your answer
![](https://koobas.hobune.stream/wayback/20220613184150im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to write Korean letters to file? 0 Answers
Create file in correct directory 3 Answers
OBB. How I can access files in OBB? 0 Answers
Load and save text from web server 2 Answers