Путь к файлу - C# (181563)

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

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

помогите пожалуйста имеется вполне работоспособный код (собирается) но неясно что куда помещать и где забирать. помещал текстовый файл в папку с проектом но безрезультатно. код взят отсюда http://stackoverflow.com/questions/9...fastest-method
Листинг программы
  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 ConsoleApplication125
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. }
  14. public void SplitFiles(int[] newFiles, string filePath, int processorCount)
  15. {
  16. using (StreamReader Reader = new StreamReader(filePath))
  17. {
  18. for (int i = 0; i < newFiles.Length; i++)
  19. {
  20. string extension = System.IO.Path.GetExtension(filePath);
  21. string temp = filePath.Substring(0, filePath.Length - extension.Length)
  22. + i.ToString();
  23. string FilePath = temp + extension;
  24. if (!File.Exists(FilePath))
  25. {
  26. for (int x = 0; x < newFiles[i]; x++)
  27. {
  28. DataWriter(Reader.ReadLine(), FilePath);
  29. }
  30. }
  31. else
  32. {
  33. return;
  34. }
  35. }
  36. }
  37. }
  38. public void DataWriter(string rowData, string filePath)
  39. {
  40. bool appendData = true;
  41. using (StreamWriter sr = new StreamWriter(filePath, appendData))
  42. {
  43. {
  44. sr.WriteLine(rowData);
  45. }
  46. }
  47. }
  48. }
  49. }

Решение задачи: «Путь к файлу»

textual
Листинг программы
  1.         static void Main(string[] args)
  2.         {
  3.             Program n = new Program();
  4.             int[] g = { 1, 2, 3 };
  5.  
  6.             n.SplitFiles(g, @"c:\1\2.txt", 1);
  7.         }
  8.                public void SplitFiles(int[] newFiles, string filePath, int processorCount)
  9.     {
  10.         using (StreamReader Reader = new StreamReader(filePath))
  11.         {
  12.             for (int i = 0; i < newFiles.Length; i++)
  13.             {
  14.                 string extension = System.IO.Path.GetExtension(filePath);
  15.                 string temp = filePath.Substring(0, filePath.Length - extension.Length)
  16.                                   + i.ToString();
  17.                 string FilePath = temp + extension;
  18.  
  19.                 if (!File.Exists(FilePath))
  20.                 {
  21.                     for (int x = 0; x < newFiles[i]; x++)
  22.                     {
  23.                         DataWriter(Reader.ReadLine(), FilePath);
  24.                     }
  25.                 }
  26.                 else
  27.                 {
  28.                     return;
  29.                 }
  30.             }
  31.         }
  32.     }
  33.  
  34.     public void DataWriter(string rowData, string filePath)
  35.     {
  36.         bool appendData = true;
  37.         using (StreamWriter sr = new StreamWriter(filePath, appendData))
  38.         {
  39.             {
  40.                 sr.WriteLine(rowData);
  41.             }
  42.         }
  43.     }
  44.  
  45. }
  46.     }

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


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

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

14   голосов , оценка 3.714 из 5

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

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

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