本文整理汇总了C#中System.IO.FileInfo.OpenText方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileInfo.OpenText方法的具体用法?C# System.IO.FileInfo.OpenText怎么用?C# System.IO.FileInfo.OpenText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了System.IO.FileInfo.OpenText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: searchFile
private bool searchFile(string p)
{
bool result = false;
System.IO.FileInfo file = new System.IO.FileInfo(p);
if (file.Exists)
{
System.IO.StreamReader sReader = file.OpenText();
result = searchFile(sReader);
sReader.Close();
}
return result;
}
示例2: readTextFile
public static string readTextFile(string name,bool forceDebugSkip)
{
string results = "";
System.IO.FileInfo dataFile;
System.IO.StreamReader textStream;
dataFile = new System.IO.FileInfo(name);
textStream = dataFile.OpenText();
if (!forceDebugSkip)
Form1.debugMessage("Starting to read " + name + ".");
results += textStream.ReadToEnd();
if (!forceDebugSkip)
Form1.debugMessage("Done reading " + name + ".\n-------\n" + results );
textStream.Close();
/* System.IO.FileStream myFile = System.IO.File.Open(name,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
for (int i=0;i<myFile.Length;i++)
results += (char)myFile.ReadByte();
myFile.Close(); */
return results;
}
示例3: LoadConfig
private static void LoadConfig()
{
lock (SyncObject)
{
Printer.PrintMessage("Loading config...");
var configInfo = new System.IO.FileInfo(ConfigFile);
if (!configInfo.Exists)
{
Printer.PrintError("#x#Error:##\n Can't find config file #b#{0}##! Using default.", ConfigFile);
}
else
{
using (var fs = configInfo.OpenText())
{
Config = Newtonsoft.Json.JsonConvert.DeserializeObject<ServerConfig>(fs.ReadToEnd());
}
if (!string.IsNullOrEmpty(Config.AutoDomains))
{
string path = System.IO.Path.GetFullPath(Config.AutoDomains);
var vaultdir = new System.IO.DirectoryInfo(path);
if (!vaultdir.Exists)
Printer.PrintError("#x#Error:##\n Can't find auto-domain location: {0}.", path);
else
{
foreach (var x in vaultdir.GetDirectories())
{
Config.Domains.Add(x.Name, x.FullName);
}
}
}
List<string> deletedDomains = new List<string>();
foreach (var z in Domains)
{
if (z.Key != string.Empty && !Config.Domains.ContainsKey(z.Key))
deletedDomains.Add(z.Key);
}
foreach (var z in deletedDomains)
Domains.Remove(z);
foreach (var x in Config.Domains)
{
System.IO.DirectoryInfo domInfo = new System.IO.DirectoryInfo(x.Value);
if (domInfo.Exists)
{
Area dm = null;
try
{
dm = Area.Load(domInfo, true, true);
}
catch
{
dm = null;
}
Printer.PrintMessage("Module: {0} => ./{1} {2}", x.Key, domInfo, dm == null ? "bare" : dm.Domain.ToString());
DomainInfo info = new DomainInfo() { Bare = dm == null, Directory = domInfo };
Domains[x.Key] = info;
if (dm != null)
dm.Dispose();
}
else
Printer.PrintError("#x#Error:##\n Can't find domain location {0}!", x.Value);
}
if ((Config.IncludeRoot.HasValue && Config.IncludeRoot.Value) || (!Config.IncludeRoot.HasValue && Domains.Count != 0))
{
using (Area a = Area.Load(BaseDirectory))
{
Domains[string.Empty] = new DomainInfo() { Bare = a == null, Directory = BaseDirectory };
Printer.PrintMessage("Root Module {1} {2}", BaseDirectory, a == null ? "bare" : a.Domain.ToString());
}
}
else if (Config.IncludeRoot.HasValue && Config.IncludeRoot.Value == false)
Domains.Remove(string.Empty);
if (Config.RequiresAuthentication)
Printer.PrintMessage("Configured to use authentication. Unauthenticated read {0}.", (Config.AllowUnauthenticatedRead ? "allowed" : "disabled"));
}
}
}
示例4: CollectFiles
private Hashtable CollectFiles(ProjectItem item)
{
Hashtable list = new Hashtable();
if (item == null) return list;
for(short i = 1; i <= item.FileCount; i++)
{
if (item.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
{
string filename = item.get_FileNames(i);
System.IO.FileInfo info = new System.IO.FileInfo(filename);
StatData data = new StatData();
data.type = StatData.FileType.Unknown;
data.fileSize = info.Length;
using (System.IO.StreamReader sr = info.OpenText())
{
string s = sr.ReadToEnd();
data.numberOfLines = System.Text.RegularExpressions.Regex.Matches(s, "\n").Count;
if (s.Contains("HibernateEntity.vsl"))
{
data.type = StatData.FileType.Entity;
}
else if (s.Contains("ValueObject.vsl"))
{
data.type = StatData.FileType.ValueObject;
}
else if (s.Contains("NSpringServiceBase.vsl"))
{
data.type = StatData.FileType.Service;
}
else if (s.Contains("Enumeration.vsl"))
{
data.type = StatData.FileType.Enumeration;
}
sr.Close();
}
list.Add(filename, data);
}
}
foreach(ProjectItem subitem in item.ProjectItems)
{
MergeHashtable(list, CollectFiles(subitem));
}
return list;
}
示例5: fromFile
public static RuleSet fromFile(string file)
{
var f = new System.IO.FileInfo(file);
if (f.Exists)
{
using (var r = f.OpenText())
{
return fromXML(r.ReadToEnd());
}
}
throw new System.IO.FileNotFoundException("File was not found");
}
示例6: Parse
public static Info Parse(string path)
{
Info fontInfo = new Info();
System.IO.FileInfo finfo = new System.IO.FileInfo(path);
System.IO.StreamReader reader = finfo.OpenText();
string line;
while ((line = reader.ReadLine()) != null)
{
string[] tokens = line.Split( ' ' );
if (tokens[0] == "common")
{
fontInfo.lineHeight = int.Parse( FindKeyValue(tokens, "lineHeight") );
fontInfo.scaleW = int.Parse( FindKeyValue(tokens, "scaleW") );
fontInfo.scaleH = int.Parse( FindKeyValue(tokens, "scaleH") );
int pages = int.Parse( FindKeyValue(tokens, "pages") );
if (pages != 1)
{
EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
return null;
}
fontInfo.numPages = pages;
if (FindKeyValue(tokens, "packed") != "")
fontInfo.isPacked = int.Parse(FindKeyValue(tokens, "packed")) != 0;
fontInfo.texturePaths = new string[pages];
for (int i = 0 ; i < pages; ++i)
fontInfo.texturePaths[i] = string.Empty;
}
else if (tokens[0] == "page")
{
int id = int.Parse(FindKeyValue(tokens, "id"));
string file = FindKeyValue(tokens, "file");
if (file[0] == '"' && file[file.Length - 1] == '"') {
file = file.Substring(1, file.Length - 2);
}
else if (file[0] == '"' && file[file.Length - 1] != '"') {
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(line, "file[\\s]*=[\\s]*\"([^\"]*)\"");
try {
file = match.Groups[1].Value;
}
catch {
file = "";
}
}
fontInfo.texturePaths[id] = file;
}
else if (tokens[0] == "char")
{
Char thisChar = new Char();
thisChar.id = int.Parse(FindKeyValue(tokens, "id"));
thisChar.x = int.Parse(FindKeyValue(tokens, "x"));
thisChar.y = int.Parse(FindKeyValue(tokens, "y"));
thisChar.width = int.Parse(FindKeyValue(tokens, "width"));
thisChar.height = int.Parse(FindKeyValue(tokens, "height"));
thisChar.xoffset = int.Parse(FindKeyValue(tokens, "xoffset"));
thisChar.yoffset = int.Parse(FindKeyValue(tokens, "yoffset"));
thisChar.xadvance = int.Parse(FindKeyValue(tokens, "xadvance"));
if (fontInfo.isPacked)
{
int chnl = int.Parse(FindKeyValue(tokens, "chnl"));
thisChar.channel = (int)Mathf.Round(Mathf.Log(chnl) / Mathf.Log(2));
}
if (thisChar.id == -1) thisChar.id = 0;
fontInfo.chars.Add(thisChar);
}
else if (tokens[0] == "kerning")
{
Kerning thisKerning = new Kerning();
thisKerning.first = int.Parse(FindKeyValue(tokens, "first"));
thisKerning.second = int.Parse(FindKeyValue(tokens, "second"));
thisKerning.amount = int.Parse(FindKeyValue(tokens, "amount"));
fontInfo.kernings.Add(thisKerning);
}
}
reader.Close();
return fontInfo;
}
示例7: AELightRun
//.........这里部分代码省略.........
{
Console.Error.WriteLine("Too many hosts specified: {0} and {1}", RMHost, args[iarg]);
SetFailure();
return;
}
RMHost = args[iarg];
}
}
MetaRemoveMachine(RMHost, DontTouchRMHost, RMForce);
}
break;
case "slavelogfind":
{
if (args.Length > 1)
{
string what = args[1];
dfs dc = LoadDfsConfig();
string[] slaves = dc.Slaves.SlaveList.Split(';');
MySpace.DataMining.Threading.ThreadTools<string>.Parallel(
new Action<string>(
delegate(string slave)
{
try
{
string netdir = Surrogate.NetworkPathForHost(slave);
System.IO.FileInfo fi = new System.IO.FileInfo(netdir + @"\slave-log.txt");
if (fi.Exists)
{
long lastmatchline = -1;
string lastmatchstring = null;
string line;
long curline = 0;
using (System.IO.StreamReader sr = fi.OpenText())
{
while (null != (line = sr.ReadLine()))
{
curline++;
if (-1 != line.IndexOf(what, StringComparison.OrdinalIgnoreCase))
{
lastmatchline = curline;
lastmatchstring = line;
}
}
}
if (-1 != lastmatchline)
{
lock (slaves)
{
Console.WriteLine("{0}({1}): {2}", fi.FullName, lastmatchline, lastmatchstring);
}
}
}
}
catch (Exception e)
{
lock (slaves)
{
Console.Error.WriteLine("Error with {0}: {1}", slave, e.Message);
}
}
}
), slaves, slaves.Length);
}
else
{
示例8: Parse
public static Info Parse(string path)
{
Info fontInfo = new Info();
System.IO.FileInfo finfo = new System.IO.FileInfo(path);
System.IO.StreamReader reader = finfo.OpenText();
string line;
while ((line = reader.ReadLine()) != null)
{
string[] tokens = line.Split( ' ' );
if (tokens[0] == "common")
{
fontInfo.lineHeight = int.Parse( FindKeyValue(tokens, "lineHeight") );
fontInfo.scaleW = int.Parse( FindKeyValue(tokens, "scaleW") );
fontInfo.scaleH = int.Parse( FindKeyValue(tokens, "scaleH") );
int pages = int.Parse( FindKeyValue(tokens, "pages") );
if (pages != 1)
{
EditorUtility.DisplayDialog("Fatal error", "Only one page supported in font. Please change the setting and re-export.", "Ok");
return null;
}
fontInfo.numPages = pages;
fontInfo.texturePaths = new string[pages];
for (int i = 0 ; i < pages; ++i)
fontInfo.texturePaths[i] = string.Empty;
}
else if (tokens[0] == "page")
{
int id = int.Parse(FindKeyValue(tokens, "id"));
string file = FindKeyValue(tokens, "file");
if (file[0] == '"' && file[file.Length - 1] == '"')
file = file.Substring(1, file.Length - 2);
fontInfo.texturePaths[id] = file;
}
else if (tokens[0] == "char")
{
Char thisChar = new Char();
thisChar.id = int.Parse(FindKeyValue(tokens, "id"));
thisChar.x = int.Parse(FindKeyValue(tokens, "x"));
thisChar.y = int.Parse(FindKeyValue(tokens, "y"));
thisChar.width = int.Parse(FindKeyValue(tokens, "width"));
thisChar.height = int.Parse(FindKeyValue(tokens, "height"));
thisChar.xoffset = int.Parse(FindKeyValue(tokens, "xoffset"));
thisChar.yoffset = int.Parse(FindKeyValue(tokens, "yoffset"));
thisChar.xadvance = int.Parse(FindKeyValue(tokens, "xadvance"));
fontInfo.chars.Add(thisChar);
}
else if (tokens[0] == "kerning")
{
Kerning thisKerning = new Kerning();
thisKerning.first = int.Parse(FindKeyValue(tokens, "first"));
thisKerning.second = int.Parse(FindKeyValue(tokens, "second"));
thisKerning.amount = int.Parse(FindKeyValue(tokens, "amount"));
fontInfo.kernings.Add(thisKerning);
}
}
reader.Close();
return fontInfo;
}
示例9: GetApplicationData
private void GetApplicationData()
{
System.IO.FileInfo FI = new System.IO.FileInfo(FileName);
SReader = FI.OpenText();
string GotData = "";
FileEntrys = new MyDictionary();
while((GotData = SReader.ReadLine()) != null)
{
string[] Data = GotData.Split('~');
FileEntrys.Add(Data[0],Data[1]);
}
SReader.Close();
}
示例10: readTextFile
public static string readTextFile(string name)
{
string results = "";
System.IO.FileInfo dataFile;
System.IO.StreamReader textStream;
dataFile = new System.IO.FileInfo(name);
try
{
textStream = dataFile.OpenText();
results += textStream.ReadToEnd();
textStream.Close();
}
catch (Exception e) { }
return results;
}
示例11: LoadSettings
private void LoadSettings()
{
System.IO.FileInfo f = new System.IO.FileInfo("settings.xml");
if (!f.Exists)
return;
var str = f.OpenText();
var xmlstr = str.ReadToEnd();
str.Close();
str.Dispose();
System.Xml.Linq.XElement xml = System.Xml.Linq.XElement.Parse(xmlstr);
foreach (var xele in xml.Elements())
{
if (xele.Name == System.Xml.Linq.XName.Get("HistoryCount"))
nudHistory.Value = decimal.Parse(xele.Value);
else if (xele.Name == System.Xml.Linq.XName.Get("SlotCount"))
nudSlots.Value = decimal.Parse(xele.Value);
else if (xele.Name == System.Xml.Linq.XName.Get("EmailAddress"))
EmailAddress = xele.Value;
else if (xele.Name == System.Xml.Linq.XName.Get("UserName"))
UserName = xele.Value;
else if (xele.Name == System.Xml.Linq.XName.Get("ServerAddress"))
ServerAddress = xele.Value;
else if (xele.Name == System.Xml.Linq.XName.Get("ServerPassword"))
Password = xele.Value;
else if (xele.Name == System.Xml.Linq.XName.Get("SMTPPort"))
Port = int.Parse(xele.Value);
else if (xele.Name == System.Xml.Linq.XName.Get("EnableSSL"))
enableSSL = bool.Parse(xele.Value);
else if (xele.Name == System.Xml.Linq.XName.Get("SubjectLine"))
SubjectLine = xele.Value;
else if (xele.Name == System.Xml.Linq.XName.Get("OpeningLine"))
OpeningLine = xele.Value;
else if (xele.Name == System.Xml.Linq.XName.Get("ClosingLine"))
ClosingLine = xele.Value;
}
}
示例12: GetPlayerString
private string GetPlayerString()
{
System.IO.FileInfo f = new System.IO.FileInfo("f10Players.xml");
if (!f.Exists)
return Properties.Settings.Default.PlayerList;
string ret = "";
try
{
var str = f.OpenText();
ret = str.ReadToEnd();
str.Close();
str.Dispose();
}
catch (Exception ex)
{
}
return ret;
}
示例13: OpenFile
private string OpenFile(string filename)
{
System.IO.FileInfo file = new System.IO.FileInfo(filename);
System.IO.StreamReader fileRead = file.OpenText();
string script = fileRead.ReadToEnd();
fileRead.Close();
return script;
}
示例14: ExecuteScript
public static bool ExecuteScript(string cn, string scriptPath)
{
try
{
System.IO.FileInfo file = new System.IO.FileInfo(scriptPath);
string script = file.OpenText().ReadToEnd();
file.OpenText().Close();
using (SqlConnection conn = new SqlConnection(cn))
{
using (SqlCommand cmd = new SqlCommand())
{
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
}
}
return true;
}
catch (Exception e)
{
throw e;
}
}
示例15: ProductCategoryUrlMovedPermanently
public ActionResult ProductCategoryUrlMovedPermanently(string badUrl, string movedUrl)
{
if (badUrl.IsNullOrTrimmedEmpty()
|| movedUrl.IsNullOrTrimmedEmpty())
{
ModelState.AddModelError("badUrl", "Bad Url or Moved Url is empty");
return View();
}
string fileName = Server.MapPath(@"/app_data/categories-compensation.txt");
var categoryCompensationListFileInfo = new System.IO.FileInfo(fileName);
var lines = new Dictionary<string, string>();
if (System.IO.File.Exists(fileName))
{
// Test de l'existence du lien
using (var content = categoryCompensationListFileInfo.OpenText())
{
while (true)
{
var line = content.ReadLine();
if (line.IsNullOrTrimmedEmpty())
{
break;
}
string[] compensation = line.Split(':');
lines.Add(compensation[0], compensation[1]);
}
}
System.IO.File.Delete(fileName);
}
if (lines.Any(i => i.Key.Equals(badUrl, StringComparison.InvariantCultureIgnoreCase)))
{
lines.Remove(badUrl);
}
lines.Add(badUrl, movedUrl);
using (var content = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Write))
{
foreach (var item in lines)
{
var line = string.Format("{0}:{1}\r\n", item.Key, item.Value);
var b = System.Text.Encoding.UTF8.GetBytes(line);
content.Write(b, 0, b.Length);
}
content.Close();
}
return View();
}