如何读入文件内容和移动文件
文件是以,分割的。
我要读取文件中的内容,并进行检验,通过的插入到数据库。
然后把文件移动到其他地方。
第一次干c#,不太明白,最好给个例子。
谢谢大家。
[解决办法]
1: 读入文件内容
using (StreamReader sr = new StreamReader( "TestFile.txt "))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
2、移动文件
File.Move(path, path2);
[解决办法]
aaa=line.split( ', ')
[解决办法]
如何验证呢?
我只进行:
数据类型和位数的验证
----------
位数的验证:array a = line.split( ', ');
for(int i=0;i <a.length;i++)
{
//a[i].length ==验证的位数
}
数据类型:
for(int i=0;i <a.length;i++)
{
//a[i] is Int32
//a[i] is String ...
}