本文介绍了IsolatedStorage API File.Append模式有'\ n'的问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 当使用IsolatedStorage API附加文件并在字符串末尾添加\ n时,文件为空,如果在字符串的开头添加它,则会删除文件然后只添加请求的数据 IsolatedStorageFile file = Isolate dStorageFile.GetUserStoreForApplication(); string fileContents =" \ n" + str +" " + txtblock1.Text; byte [] data = Encoding.UTF8.GetBytes(fileContents); using(IsolatedStorageFileStream stream = new IsolatedStorageFileStream(" Th.txt",FileMode.Append,file)) { stream.Seek(0,SeekOrigin.End); stream.Write(data,0,data.Length); stream.Close(); } 那么在这种情况下我该怎么做才能添加一个新行然后写入文件?解决方案 我没有看到你描述的行为......你如何验证文件内容? When appending a file using IsolatedStorage API and adding a \n at the end of the string the file is empty and if adding it in the beginning of the string it erases the file then adds the requested data only IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication(); string fileContents = "\n"+str+ " " + txtblock1.Text; byte[] data = Encoding.UTF8.GetBytes(fileContents);using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("Th.txt", FileMode.Append, file)) { stream.Seek(0, SeekOrigin.End); stream.Write(data, 0, data.Length); stream.Close(); }So what should I do in that case to add a new line then write in the file ? 解决方案 I'm not seeing the behavior you describe... How are you verifying the file contents? 这篇关于IsolatedStorage API File.Append模式有'\ n'的问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 12:56