- 积分
- 0
- 注册时间
- 2011-1-3
- 仿真币
-
- 最后登录
- 1970-1-1
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace TextToFile
{
class Program
{
private const string FILE_NAME_1 = "Abaqus.txt";
private const string FILE_NAME_2 = "Flac3D.txt";
public static void Main(string[] args)
{
if (!File.Exists(FILE_NAME_1))
{
Console.WriteLine("{0} does not exist.", FILE_NAME_1);
return;
}
if (File.Exists(FILE_NAME_2))
{
Console.WriteLine("{0} already exists.", FILE_NAME_2);
return;
}
string[] lines = System.IO.File.ReadAllLines(@"F:\c#程序\TextToFile\TextToFile\bin\Debug\Abaqus.txt", Encoding.Default);
for (int i = 0; i <= 6170; i++)
{
string[] strs = lines[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
strs[0] = "G" + strs[0];
using (StreamWriter sw = File.CreateText(FILE_NAME_2))
{
sw.WriteLine("{0}{1}{2}{3}", strs[0], strs[1], strs[2], strs[3]);
}
}
}
}
}
小弟试着从一个文本文件中读入数据,稍作修改后输出到另一个文本文件中。程序如上,这里有一个问题,循环怎么只进行一次呢?输出的文本中只有一行数据,请问各位牛人朋友!另祝各位国庆快乐!
|
|