读取管道分隔文件但无法看到输出 [英] Reading a pipe delimited file but cant see the output
本文介绍了读取管道分隔文件但无法看到输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在尝试读取管道分隔文件,但无法看到输出只能看到空白屏幕
另外如果我想输出到文件我该怎么做。
下面是我的代码我做错了。
Hi
I am trying to read pipe delimited file but cant see the output can see only blank screen
Also if I want to output to a file how do I do it.
below is my code what I am doing wrong.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] strfilepath = Directory.GetFiles(@"C:\test.txt");
List<string> list = new List<string>();
try
{
foreach (string FiletoRead in strfilepath)
{
System.IO.StreamReader file = new System.IO.StreamReader(FiletoRead);
string read;
while ((read = file.ReadLine()) != null)
{
string[] lineData = read.Split('|');
for (int i = 0; i < lineData.Length; i++)
{
list.Add(lineData[i]);
}
file.Close();
{
Console.WriteLine("{0}", lineData[0]);
Console.Read();
}
}
}
}
catch(Exception)
{
Console.WriteLine("No File");
}
}
}
}
请帮助。
please help.
推荐答案
您正在输出lineData [0],大概是空的(或至少是不可打印的)。
运行un debug,在循环内部插入断点,并检查lineData [i]的值以查看它实际读取的内容
You are outputting lineData[0] which, presumably, is empty (or at least unprintable).
Run un debug, puit a breakpoint inside the loop, and check the values of lineData[i] to see what it is actually reading
请参阅本指南:
http://msdn.microsoft。 com / en-us / library / 94223t4d.aspx [ ^ ]
从那里开始,将每一行打印到控制台。然后开始通过|添加每行的拆分字符并打印出来,然后添加列表。尝试以小块的形式完成程序,你会发现它更容易。
Please see this guide:
http://msdn.microsoft.com/en-us/library/94223t4d.aspx[^]
Start there, print each line to the console. Then start adding the splitting of each line by the | characters and print those out, then add the list. Try doing the program in small chunks, you'll find it easier to do.
这篇关于读取管道分隔文件但无法看到输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文