- Home /
Can't open the file with File.Open/File.OpenRead
Can't open file with File.Open/File.OpenRead. System sees that file exists, but the FileNotFoundException is thrown when it tries to read file. Here's the code:
if (File.Exists(@"D:\records.dat"))
{
using (Stream str = File.OpenRead(@"D:\records.dat"))
{
Records = (scoreboardContainer)Bf.Deserialize(stream);
}
}
else Debug.Log("file not exists");
Need an advice, how to fix this.
Fixed this. Object should be serialized from the same assembly which attended to read it. Didn't know about that.
Answer by USMANHEART · Dec 10, 2020 at 06:48 AM
using (FileStream fs = File.OpenRead(path)) { byte[] b = new byte[1024]; UTF8Encoding temp = new UTF8Encoding(true); while (fs.Read(b,0,b.Length) > 0) { Console.WriteLine(temp.GetString(b)); } }
Your answer
Follow this Question
Related Questions
"IOException: Sharing violation on path" when Loading Data to Overwrite Save 1 Answer
C# Serialization error on Mobile using FileStream 1 Answer
Does SerializeField work when extending the Input System? 1 Answer
File saving error 1 Answer
Class variable wont show up in inspector with new Unity Input System 1 Answer