Недопустимый двоичный формат входного потока - C#

Узнай цену своей работы

Формулировка задачи:

Всем привет! Возникла такая ошибка: "Недопустимый двоичный формат входного потока." В чем может быть проблема? Вот код:
Листинг программы
  1. namespace pr
  2. {
  3. [Serializable]
  4. class logic
  5. {
  6. StringBuilder organisation;
  7. StringBuilder telephone;
  8. StringBuilder contact;
  9. StringBuilder adress;
  10. public logic()
  11. {
  12. organisation = new StringBuilder("ГАЗПРОМ", 80);
  13. adress = new StringBuilder("улица Руставелли",100);
  14. telephone = new StringBuilder("88006005050", 11);
  15. contact = new StringBuilder("www.bbb.com", 100);
  16. }
  17. public logic(string organisation, string adress, string telephone, string contact)
  18. {
  19. this.organisation = new StringBuilder(organisation, 80);
  20. this.adress = new StringBuilder(adress, 100);
  21. this.telephone = new StringBuilder(telephone, 11);
  22. this.contact = new StringBuilder(contact, 100);
  23. }
  24. public void AddToFile(string path)
  25. {
  26. FileStream f = new FileStream(path, FileMode.Append);
  27. BinaryFormatter bw = new BinaryFormatter();
  28. bw.Serialize(f, this, null);
  29. f.Close();
  30. }
  31. public static string Show(string path)
  32. {
  33. BinaryFormatter formatter = new BinaryFormatter();
  34. string ans = "";
  35. using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
  36. {
  37. while (fs.Position < fs.Length)
  38. {
  39. logic newLogic = (logic)formatter.Deserialize(fs);
  40. ans += newLogic.organisation + "," +newLogic.adress+","+ newLogic.telephone + "," + newLogic.contact + "," + "";
  41. }
  42. }
  43. return ans;
  44. }
  45. public long find(string path)
  46. {
  47. BinaryFormatter formatter = new BinaryFormatter();
  48. using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
  49. {
  50. while (fs.Position < fs.Length)
  51. {
  52. long pos = fs.Position;
  53. logic newLogic = (logic)formatter.Deserialize(fs);
  54. if (newLogic.organisation.Equals(this.organisation))
  55. return pos;
  56. }
  57. }
  58. return -1;
  59. }
  60. public void correct(string path, long pos)
  61. {
  62. BinaryFormatter formatter = new BinaryFormatter();
  63. using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
  64. {
  65. fs.Seek(pos, SeekOrigin.Begin);
  66. formatter.Serialize(fs, this, null);
  67. }
  68. }
  69. }
  70. }

Решение задачи: «Недопустимый двоичный формат входного потока»

textual
Листинг программы
  1. for (int i = 0; i < b.Length; i++)

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

11   голосов , оценка 4.182 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы