尝试做dat文件的存档,在filestream了一个saveinfo类,目录是正确的,实例化了,filemode是openorcreate fileaccess是readwrite
并且close了saveinfo类
建立了一个binarywriter sv1的二进制写入,并且实例化
但是在尝试创建存档写入数据的时候,就会报错:stream was not writable“流没有写入权限”
报错图片如下
整段代码如下
int firstlevel = 1;
int firstcoin = 1;
int firstrainbowstone = 0;
int firstlevelexp = 0;
int firstcharactorexp = 0;
Directory.CreateDirectory(System.AppDomain.CurrentDomain.BaseDirectory + @"\saves\save1");//新建存档一文件夹
FileStream save1 = File.Create(System.AppDomain.CurrentDomain.BaseDirectory + @"\saves\save1\save1.dat");//新建存档一信息并初始化
save1.Close();
FileStream saveinfo = new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + @"\saves\save1\save1.dat", FileMode.OpenOrCreate,FileAccess.ReadWrite);
saveinfo.Close();
BinaryWriter sv1 = new BinaryWriter(saveinfo);
//写入二进制数据
sv1.Write(firstlevel);
sv1.Write(firstcoin);
sv1.Write(firstrainbowstone);
sv1.Write(firstlevelexp);
sv1.Write(firstcharactorexp);
sv1.Close();