BinaryWriter问题。。。。急
1.private void button1_Click(object sender, EventArgs e)
2.{
3. string fileName = "MyNew.data";
4. if (File.Exists(fileName))
5. {
6. MessageBox.Show("当前文件已经存在");
7. }
8. else
9. {
10. FileStream fs = new FileStream(fileName, FileMode.Create);
12. BinaryWriter writer = new BinaryWriter(fs);
13. writer.Write(textBox1.Text);
14. MessageBox.Show("写入文件成功");
15. textBox1.Text = "";
16. writer.Close();
17. fs.Close();
18. }
19.}
20.private void button3_Click(object sender, EventArgs e)
21.{
22. string fileName = "MyNew.data";
23. if (!(File.Exists(fileName)))
24. {
25. MessageBox.Show("当前文件不存在");
26. return;
27. }
28. string strData = "";
29. FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
30. BinaryReader reader = new BinaryReader(fs);
31. strData = reader.ReadString();
32. for (int i = 0; i < 200; i++)
33. {
34. if (i == 0)
35. {
36. strData += reader.ReadInt32().ToString();
37. }
38. else
39. {
40. strData += "||" + reader.ReadInt32().ToString();
41. }
42. }
43. textBox2.Text = strData;
44. fs.Close();
45. reader.Close();
第36行提示无法在流的结尾外读取?怎么回事呢? --------------------编程问答-------------------- 31. strData = reader.ReadString();
你这句是干什么?? --------------------编程问答-------------------- BinaryReader br = new BinaryReader(fs);
MessageBox.Show(br.ReadInt32().ToString());
--------------------编程问答--------------------
调用BinaryReader的ReadString方法 --------------------编程问答--------------------
我是说你应该删掉这个方法,这个方法有点像读BSTR
补充:.NET技术 , C#