首页 > 其他 > 详细

批量修改文件内容

时间:2016-03-20 13:09:34      阅读:130      评论:0      收藏:0      [点我收藏+]
 1 using System;
 2 using System.IO;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace UsefulProject
 9 {
10     public class Program
11     {
12         static string line;
13         static int linesnum;
14 
15         static void Main(string[] args)
16         {
17             ReviseFileContent(@"D:\mylist.txt");
18 
19             Console.WriteLine(linesnum);
20             Console.ReadKey();
21         }
22          
23         public static void ReviseFileContent(string path) 
24         {
25             StreamReader sr = new StreamReader(@"D:\list.txt", Encoding.Default);
26             StreamWriter sw = new StreamWriter(@"D:\mylist.txt");
27 
28             while (true)
29             {
30                 if ((line = sr.ReadLine()) != null)
31                 {
32                     string[] ss = line.Split(.);
33                     string s = ss[0].ToString() + "S." + ss[1].ToString();
34 
35                     sw.WriteLine(s);
36 
37                     linesnum++;
38                 }
39             }
40 
41             sw.Close();
42             sr.Close();
43 
44         }
45     }
46 }

 奇怪的是linesnum在控制台显示不出来了,如果将函数ReviseFileContent注释掉,可以正常显示,不想了吃饭去……

批量修改文件内容

原文:http://www.cnblogs.com/leejxyz/p/5297431.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!