本文整理汇总了C#中System.IO.FileInfo.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.ReadLine方法的具体用法?C# FileInfo.ReadLine怎么用?C# FileInfo.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.ReadLine方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllTheTeams
public IEnumerable<IProvideTeamInformation> GetAllTheTeams()
{
using (var reader = new FileInfo(@"data\football.dat").OpenText())
{
string line;
Enumerable.Range(1, 5).Each(x => reader.ReadLine());
while ((line = reader.ReadLine()) != null)
{
if(IsValidLine(line))
yield return ParseLine(line);
}
}
}
示例2: ReadFiles
// [Fact()]
public void ReadFiles()
{
var file = Path.GetTempFileName();
var info = new FileInfo(file);
File.AppendAllLines(file, Enumerable.Range(1, 100000).Select(i => $"This is line number {i}"));
var indexer = new LineIndexer(info);
var items = indexer.ReadToEnd().ToArray();
var actual = File.ReadAllLines(file).ToArray();
var toRead = Enumerable.Range(0, 1000)
.Select(i => items.InferPosition(i))
.ToArray();
;
var largest = toRead.Last();
var fileLength = file.Length;
Console.WriteLine();
var convertedLines = info.ReadLine(toRead, (li, str) =>
{
return str;
}).ToArray();
File.Delete(file);
}
示例3: Main
static void Main(string[] args)
{
// Initialise the pattern provider with a list of 4 properties.
using (var pattern = new PatternWrapper(
new FileInfo("..\\..\\..\\..\\..\\data\\51Degrees-LiteV3.2.dat").FullName,
new[] { "Id", "DeviceType", "IsMobile", "ScreenPixelsWidth", "ScreenPixelsHeight" }))
{
// Initialise the trie provider with a data file and a list of 4 properties.
using (var trie = new TrieWrapper(
new FileInfo("..\\..\\..\\..\\..\\data\\51Degrees-LiteV3.2.trie").FullName,
new[] { "Id", "DeviceType", "IsMobile", "ScreenPixelsWidth", "ScreenPixelsHeight" }))
{
// IMPORTANT: For a full list of properties see: https://51degrees.com/resources/property-dictionary
using (var reader = new FileInfo(args.Length > 0 ? args[0] : "..\\..\\..\\..\\..\\data\\20000 User Agents.csv").OpenText())
{
var start = DateTime.UtcNow;
Console.WriteLine("Started -> {0}", start);
var line = reader.ReadLine();
while (line != null)
{
using (var patternResults = pattern.Match(line.Trim()))
{
Output(pattern, patternResults);
}
using (var trieResults = trie.Match(line.Trim()))
{
Output(trie, trieResults);
}
line = reader.ReadLine();
}
Console.WriteLine("Elapsed Time -> {0} seconds", (DateTime.UtcNow - start).TotalSeconds);
}
}
}
Console.ReadKey();
}
示例4: FileWhereThereIsAProblemIndexing
//[Fact()]
public void FileWhereThereIsAProblemIndexing()
{
var file = Path.GetTempFileName();
var info = new FileInfo(@"U:\Downloads\InventairePerpetuel.txt");
var indexer = new LineIndexer(info);
var indexed = indexer.ReadToEnd().ToArray();
var indicies = new LineIndicies(indexed, indexer.Encoding,indexer.LineFeedSize);
// var tail = indicies.GetTail(new ScrollRequest(1)).ToArray();
var tail = indicies.GetTail(new ScrollRequest(1)).ToArray();
Console.WriteLine(indicies.Lines.Last());
var convertedLines = info.ReadLine(tail, (li, str) =>
{
Console.WriteLine(li.Size);
Console.WriteLine(str.Length);
return str;
}, indicies.Encoding).ToArray();
}
示例5: MakeSureContentsFileIsUpdated
public void MakeSureContentsFileIsUpdated()
{
var dsinfo = MakeDSInfo("ds1.1.1");
var d = new DirectoryInfo("MakeSureContentsFileIsUpdated");
if (d.Exists)
{
d.Delete(true);
}
d.Create();
var f = new FileInfo(Path.Combine(d.FullName, "contents.txt"));
using (var wr = f.CreateText())
{
wr.WriteLine("otherdataset.data.set gwatts");
}
var ld = new LinuxMirrorDownloaderPretend(d, dsinfo.Name);
var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
var r = gf.GetDS(dsinfo);
Assert.IsTrue(f.Exists);
Assert.AreEqual("otherdataset.data.set gwatts", f.ReadLine(1));
Assert.IsTrue(f.ReadLine(2).StartsWith(dsinfo.Name));
}
示例6: MakeSureContentsFileIsCreated
public void MakeSureContentsFileIsCreated()
{
var dsinfo = MakeDSInfo("ds1.1.1");
var d = new DirectoryInfo("MakeSureContentsFileIsCreated");
if (d.Exists)
{
d.Delete(true);
}
var ld = new LinuxMirrorDownloaderPretend(d, dsinfo.Name);
var gf = new GRIDFetchToLinuxVisibleOnWindows(d, ld, "/bogus/files/store");
var r = gf.GetDS(dsinfo);
var f = new FileInfo(Path.Combine(d.FullName, "contents.txt"));
Assert.IsTrue(f.Exists);
Assert.IsTrue(f.ReadLine().StartsWith(dsinfo.Name));
}
示例7: ReadIMUFile
public ArrayList ReadIMUFile(string filePath, double startTow, double endTow)
{
ArrayList list = new ArrayList();
try
{
StreamReader reader = new FileInfo(filePath).OpenText();
double num = 0.0;
int num2 = 0;
int num3 = 0;
bool flag = false;
string str = string.Empty;
string input = reader.ReadLine();
while (input != null)
{
if (!flag && input.Contains("SW Version"))
{
string pattern = "SW Version*(?<swVer>.*)";
Regex regex = new Regex(pattern, RegexOptions.Compiled);
if (regex.IsMatch(input))
{
str = regex.Match(input).Result("${swVer}");
flag = true;
}
}
string[] strArray = input.Split(new char[] { ',' });
if (strArray.Length <= 20)
{
goto Label_0302;
}
if (strArray[0] == "28")
{
num3 = Convert.ToInt16(strArray[0x13]);
if (num2 < num3)
{
num2 = num3;
num = (uint) Convert.ToDouble(strArray[4]);
}
}
if (!(strArray[0] == "41") || (Convert.ToInt16(strArray[2]) <= 0))
{
goto Label_0302;
}
PositionInfo.PositionStruct struct2 = new PositionInfo.PositionStruct();
struct2.NavType = Convert.ToUInt16(strArray[2]);
int num4 = 8;
struct2.TOW = (uint) (Convert.ToDouble(strArray[num4 / 2]) / 1000.0);
if (startTow > 0.0)
{
if (struct2.TOW >= startTow)
{
if ((endTow > 0.0) && (struct2.TOW > endTow))
{
return list;
}
goto Label_0190;
}
input = reader.ReadLine();
continue;
}
if ((endTow > 0.0) && (struct2.TOW > endTow))
{
return list;
}
Label_0190:
struct2.RxTime_Hour = Convert.ToInt32(strArray[num4++]);
struct2.RxTime_Minute = Convert.ToInt32(strArray[num4++]);
struct2.RxTime_second = (ushort) (Convert.ToDouble(strArray[num4++]) / 1000.0);
struct2.SatellitesUsed = Convert.ToUInt32(strArray[num4++]);
struct2.Latitude = Convert.ToDouble(strArray[num4++]) / 10000000.0;
struct2.Longitude = Convert.ToDouble(strArray[num4++]) / 10000000.0;
struct2.Altitude = Convert.ToDouble(strArray[num4++]) / 100.0;
struct2.Speed = Convert.ToDouble(strArray[num4 + 2]) / 100.0;
struct2.Heading = Convert.ToDouble(strArray[num4 + 3]) / 100.0;
struct2.NumSVInFix = Convert.ToUInt16(strArray[num4 + 0x12]);
struct2.HDOP = Convert.ToDouble(strArray[num4 + 0x13]) / 5.0;
if (struct2.TOW == num)
{
struct2.MaxCN0 = num2;
}
else
{
struct2.MaxCN0 = 0.0;
}
num2 = 0;
num3 = 0;
struct2.SW_Version = str;
list.Add(struct2);
Label_0302:
input = reader.ReadLine();
}
}
catch (Exception exception)
{
throw exception;
}
return list;
}
示例8: WriteWholeFile
public void WriteWholeFile()
{
var data = new List<string[]>();
data.Add(new string[] { "column1line1", "column2line1" });
data.Add(new string[] { "column1line2", "column2line2" });
csvReaderWriter.Open(TestOutputFile, CSVReaderWriter.Mode.Write);
csvReaderWriter.WriteWholeFile(data);
csvReaderWriter.Close();
StreamReader reader = new FileInfo(TestOutputFile).OpenText();
Assert.That(reader.ReadLine(), Is.EqualTo("column1line1" + "\t" + "column2line1"));
Assert.That(reader.ReadLine(), Is.EqualTo("column1line2" + "\t" + "column2line2"));
reader.Close();
}
示例9: Scene
public Scene(string inputFilename)
{
triangles = new List<Triangle>();
quads = new List<Quad>();
bullets = new List<Bullet>();
hud = new HUD();
StreamReader reader = new FileInfo(inputFilename).OpenText();
string line;
Dictionary<string, Vector> loadedVertices = new Dictionary<string, Vector>();
Dictionary<string, int> loadedTextures = new Dictionary<string, int>();
Dictionary<string, float> values = new Dictionary<string,float>();
int texturesCount = 0;
textures = new uint[texturesCount];
int lineCounter = 0;
while (true)
{
line = reader.ReadLine();
if (line == null)
break;
line = System.Text.RegularExpressions.Regex.Replace(line, "#.*", "", System.Text.RegularExpressions.RegexOptions.Compiled);
lineCounter++;
if (line == "")
continue;
if (line.IndexOf("clear vertices") == 0)
loadedVertices = new Dictionary<string, Vector>();
else if (line.IndexOf("start") == 0)
{
#region start
string[] parts = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 6)
{
throw new Exception("line.split for start did not make the right length array. line " + lineCounter.ToString());
}
cameraPosition.x = GetFloat(parts[1], values);
cameraPosition.y = GetFloat(parts[2], values);
cameraPosition.z = GetFloat(parts[3], values);
lookAngleX = GetFloat(parts[4], values);
lookAngleY = GetFloat(parts[5], values);
#endregion
}
else if (line.Contains("vertex"))
{
#region vertex
try
{
string[] parts = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 5)
throw new Exception("line.Split for Vector did not make the right length array. line " + lineCounter.ToString());
string name = parts[1];
float x = GetFloat(parts[2], values);
float y = GetFloat(parts[3], values);
float z = GetFloat(parts[4], values);
loadedVertices.Add(name, new Vector(x, y, z));
}
catch (Exception e)
{
throw new Exception("error parsing input file. line " + lineCounter.ToString() + " . message: " + e.Message);
}
#endregion
}
else if (line.Contains("quad"))
{
#region quad
string[] parts;
parts = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 10)
{
throw new Exception("line.split for quad was not the right length. line: " + lineCounter.ToString());
}
if (parts[5] == "color")
{
float red = GetFloat(parts[6], values);
float green = GetFloat(parts[7], values);
float blue = GetFloat(parts[8], values);
MyColor color = new MyColor(red, green, blue);
string name = parts[9];
Vector v1 = loadedVertices[parts[1]];
Vector v2 = loadedVertices[parts[2]];
Vector v3 = loadedVertices[parts[3]];
//.........这里部分代码省略.........
示例10: LoadPO
private void LoadPO(string file, bool ignore_revision = false)
{
int line = 0;
int strings = 0;
string Quote = "\"";
Dictionary<string, int> line_continuations = new Dictionary<string, int>();
Dictionary<int, string> plurals = new Dictionary<int, string>();
string comment_running = string.Empty;
int min = int.MaxValue;
int max = int.MinValue;
string[] folders = System.IO.Path.GetDirectoryName(file).Split(System.IO.Path.DirectorySeparatorChar);
string language = folders[folders.Count() - 1];
string header = "msgid \"\"\r\nmsgstr \"\"";
StreamReader po = new FileInfo(file).OpenText();
string po_line = po.ReadLine().Trim(); line += 1;
for (int i = 0; i <= present.GetUpperBound(0); i++)
{
present[i] = false;
current_text[i] = string.Empty;
}
Console.Write("Reading '" + file + "' ... ");
while (po_line.StartsWith("#"))
{
po_line = po.ReadLine().Trim(); line += 1;
}
po_line += "\r\n" + po.ReadLine(); line += 1;
if (po_line == header)
{
po_line = po.ReadLine(); line += 1;
while (po_line.Length > 0)
{
string name = po_line.Substring(0, po_line.IndexOf(":"));
string value = po_line.Substring(po_line.IndexOf(":") + 1).Trim();
if (name[0] == '\"') name = name.Substring(1);
if (value[value.Length - 1] == '\"') value = value.Substring(0, value.Length - 1);
if (ignore_revision == false) revision_info.Add(name, value);
po_line = po.ReadLine(); line += 1;
}
if (ignore_revision == false) revision_info.Add("Language-Name", language);
bool need_read = false;
int id = int.MinValue;
int line_contd = keyword_unknown;
int plural_case = -1;
while (po.EndOfStream == false)
{
if (need_read)
{
po_line = po.ReadLine().Trim(); line += 1;
}
else
{
need_read = true; // read on the next pass
}
if (po_line.Length == 0)
{
if (current_text[keyword_msg_context].Length > 0)
{
try
{
if (id > max) max = id;
if (id < min) min = id;
if (current_text[keyword_msg_plural] == string.Empty && plurals.Count == 0)
{
map.Add(id, new TextResource(id, current_text[keyword_msg_id], current_text[keyword_msg_text], comment_running));
}
else
{
map.Add(id, new TextResource(id, current_text[keyword_msg_id], current_text[keyword_msg_text], comment_running, current_text[keyword_msg_plural], plurals));
}
strings++;
}
catch (ArgumentException ex)
{
throw new FileLoadException(string.Format("Duplicate message id on line {0} in file {1}. {2}", line, file, ex));
}
}
comment_running = string.Empty;
id = int.MinValue;
line_contd = keyword_unknown;
for (int i = 0; i <= present.GetUpperBound(0); i++)
{
present[i] = false;
current_text[i] = string.Empty;
}
plurals = new Dictionary<int, string>();
}
else
{
//.........这里部分代码省略.........
示例11: LoadPO
private void LoadPO(string file, bool ignore_revision = false)
{
int line = 0;
int strings = 0;
string comment = string.Empty;
string comment_running = comment;
int min = int.MaxValue;
int max = int.MinValue;
string[] folders = System.IO.Path.GetDirectoryName(file).Split(System.IO.Path.DirectorySeparatorChar);
string language = folders[folders.Count() - 1];
string header = "msgid \"\"\r\nmsgstr \"\"";
StreamReader po = new FileInfo(file).OpenText();
string h = po.ReadLine().Trim(); line += 1;
Console.Write("Reading '" + file + "' ... ");
while (h.StartsWith("#"))
{
h = po.ReadLine().Trim(); line += 1;
}
h += "\r\n" + po.ReadLine(); line += 1;
if (h == header)
{
h = po.ReadLine(); line += 1;
while (h.Length > 0)
{
string name = h.Substring(0, h.IndexOf(":"));
string value = h.Substring(h.IndexOf(":") + 1).Trim();
if (name[0] == '\"') name = name.Substring(1);
if (value[value.Length - 1] == '\"') value = value.Substring(0, value.Length - 1);
if (ignore_revision == false) revision_info.Add(name, value);
h = po.ReadLine(); line += 1;
}
if (ignore_revision == false) revision_info.Add("Language-Name", language);
string numid = "";
string key;
string text;
while (po.EndOfStream == false)
{
numid = po.ReadLine().Trim(); line += 1;
if (numid.StartsWith("msgctxt \"#") == true)
{
comment = comment_running;
comment_running = string.Empty;
numid = numid.Substring("msgctxt \"#".Length);
if (numid.EndsWith("\"")) numid = numid.Substring(0, numid.Length - 1);
key = po.ReadLine().Trim(); line += 1;
if (key.StartsWith("msgid \"") == true)
{
key = key.Substring("msgid \"".Length);
if (key.EndsWith("\"")) key = key.Substring(0, key.Length - 1);
}
else
throw new FileLoadException(string.Format("Expecting textual message id on line {0} in file {1}.", line, file));
text = po.ReadLine().Trim(); line += 1;
if (text.StartsWith("msgstr \"") == true)
{
text = text.Substring("msgstr \"".Length);
if (text.EndsWith("\"")) text = text.Substring(0, text.Length - 1);
}
else
throw new FileLoadException(string.Format("Expecting resource message on line {0} in file {1}.", line, file));
string empty = po.ReadLine(); line += 1;
int id = 0;
if (int.TryParse(numid, out id) == false)
throw new FileLoadException(string.Format("Expecting numeric message id on line {0} in file {1}.", line, file));
try
{
if (id > max) max = id;
if (id < min) min = id;
map.Add(id, new TextResource(id, key, text, comment));
comment = string.Empty;
strings++;
}
catch (ArgumentException ex)
{
throw new FileLoadException(string.Format("Duplicate message id on line {0} in file {1}. {2}", line, file, ex));
}
}
else
if (numid.Length > 0 && numid.StartsWith("#") == false)
{
throw new FileLoadException(string.Format("Expecting numeric message id on line {0} in file {1}.", line, file));
}
else
{
if (numid.Length > 0 && numid.StartsWith("#empty string") == false)
//.........这里部分代码省略.........