Gestione_File.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. namespace Eserciziotep4
  8. {
  9. static class Gestione_File
  10. {
  11. static string Pacht = @"c:\document\pippo\";
  12. static string NomeFile = @"text.dat";
  13. static string Pachtd = Pacht + NomeFile;
  14. public static void MakeDirecotry()
  15. {
  16. try
  17. {
  18. Directory.CreateDirectory(Pacht);
  19. FileStream fs = File.Create(Pachtd);
  20. fs.Close();
  21. } catch (IOException e)
  22. {
  23. Console.WriteLine(e.Message);
  24. }
  25. }
  26. public static void Scrivi(string nome,string cognome)
  27. {
  28. try
  29. {
  30. //FileStream fe = File.OpenWrite(Pachtd);
  31. BinaryWriter bw = new BinaryWriter(File.Open(Pachtd,FileMode.Open));
  32. bw.Write(nome);
  33. bw.Write(cognome);
  34. bw.Close();
  35. }catch(IOException e)
  36. {
  37. Console.WriteLine(e.Message);
  38. }
  39. }
  40. public static string[] Leggi()
  41. {
  42. string c1=null;
  43. string[] p = new string[2];
  44. try
  45. {
  46. //FileStream fe = File.OpenRead(Pachtd);
  47. BinaryReader br = new BinaryReader((File.Open(Pachtd, FileMode.Open)));
  48. for (int i = 0; i < 2; i++)
  49. {
  50. c1 = br.ReadString();
  51. p[i] = c1;
  52. }
  53. br.Close();
  54. // fe.Close();
  55. }catch(IOException e)
  56. {
  57. Console.WriteLine(e.Message);
  58. }
  59. return p;
  60. }
  61. }
  62. }