本文整理汇总了C#中FileInfo.OpenText方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.OpenText方法的具体用法?C# FileInfo.OpenText怎么用?C# FileInfo.OpenText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileInfo
的用法示例。
在下文中一共展示了FileInfo.OpenText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
// Use this for initialization
void Start()
{
originalFile = new FileInfo(Application.dataPath + "/questions.txt");
if (originalFile != null && originalFile.Exists)
{
reader = originalFile.OpenText();
}
else
{
textfile = (TextAsset)Resources.Load("embedded2", typeof(TextAsset));
reader = new StringReader(textfile.text);
}
string lineOfText;
int lineNumber = 0;
while ((lineOfText = reader.ReadLine()) != null)
{
lineOfText = lineOfText.Replace("''", "'");
if (lineNumber%5 == 0)
questions.Add(lineOfText);
else
answers.Add(lineOfText);
lineNumber++;
}
SendMessage("Gather");
}
示例2: LoadMapping
void LoadMapping()
{
FileInfo theSourceFile = new FileInfo (path);
StreamReader reader = theSourceFile.OpenText();
string text = reader.ReadToEnd();
reader.Close();
string[] lines = text.Split('\r');
Client_lowerLeft_x = float.Parse(lines[1]);
Client_lowerLeft_y = float.Parse(lines[2]);
Client_lowerRight_x = float.Parse(lines[3]);
Client_lowerRight_y = float.Parse(lines[4]);
Client_upperRight_x = float.Parse(lines[5]);
Client_upperRight_y = float.Parse(lines[6]);
Client_upperLeft_x = float.Parse(lines[7]);
Client_upperLeft_y = float.Parse(lines[8]);
Server_lowerLeft_x = float.Parse(lines[10]);
Server_lowerLeft_y = float.Parse(lines[11]);
Server_lowerRight_x = float.Parse(lines[12]);
Server_lowerRight_y = float.Parse(lines[13]);
Server_upperRight_x = float.Parse(lines[14]);
Server_upperRight_y = float.Parse(lines[15]);
Server_upperLeft_x = float.Parse(lines[16]);
Server_upperLeft_y = float.Parse(lines[17]);
}
示例3: Start
void Start()
{
introText = "";
showIntroText = true;
intro = new ArrayList();
FileInfo theSourceFile = new FileInfo("Assets/StoryAssets/Level1.txt");
StreamReader reader = theSourceFile.OpenText();
SpeechBubbleText = GameObject.FindWithTag("SpeechBubbleText").GetComponent<GUIText>() as GUIText;
string line;
int i = 0;
currentLine = 0;
do
{
line = reader.ReadLine();
intro.Add(line);
i++;
} while (line != null);
do
{
if (currentLine >= 5)
{
showIntroText = false;
}
SpeechBubbleText.text = (intro[currentLine]).ToString();
StartCoroutine(HideSpeechBubble());
} while (showIntroText == true);
}
示例4: Start
void Start()
{
originalFile = new FileInfo(Application.dataPath + "/sentences.txt");
if(originalFile != null && originalFile.Exists)
{
reader = originalFile.OpenText();
}
else
{
textFile = (TextAsset)Resources.Load("embedded", typeof(TextAsset));
reader = new StringReader(textFile.text);
}
string lineOfText;
int lineNumber = 0;
while((lineOfText = reader.ReadLine()) != null)
{
if(lineNumber %2 == 0)
{
//even lines
sentences.Add(lineOfText);
}
else
{
//odd lines
clues.Add(lineOfText);
}
lineNumber++;
}
SendMessage("Gather");
}
示例5: create_style
public StringBuilder create_style(String type)
{
FileInfo xmlfile = new FileInfo(HttpContext.Current.Server.MapPath("~/App_Data/Styles/style.xml"));
StringBuilder sb = new StringBuilder(xmlfile.OpenText().ReadToEnd());
sb.Replace("@[email protected]", type);
return sb;
}
示例6: count
// Some comment for the test
private void count(string root)
{
foreach (string newRoot in Directory.GetDirectories(root))
{
count(newRoot);
}
foreach (string filePath in Directory.GetFiles(root))
{
FileInfo fi = new FileInfo(filePath);
if(fi.Extension.Equals(".cs"))
{
int cnt = 0;
StreamReader reader = fi.OpenText();
string line;
bool commentBlock = false;
while((line = reader.ReadLine()) != null)
{
if(!commentBlock && !lineComment.IsMatch(line))
{
if(commentBlockStart.IsMatch(line))
{
commentBlock = true;
} else if (!emptyLine.IsMatch(line)) {
cnt++;
}
} else if (commentBlockEnd.IsMatch(line)) {
commentBlock = false;
}
}
Console.WriteLine("{0} got {1} lines with code", filePath, cnt);
}
}
}
示例7: Start
// Use this for initialization
void Start()
{
originalFile = new FileInfo (Application.dataPath + "/sentences.txt");
if (originalFile != null && originalFile.Exists)
{
reader = originalFile.OpenText ();
}
else
{
textFile = (TextAsset)Resources.Load ("embedded", typeof(TextAsset));
reader = new StringReader (textFile.text);
}
string lineOfText;
int lineNumber = 0;
//tell teh reader to read a line of text, and store that in the line of TextVariable
//continue doing this until there are no lines left
while ((lineOfText = reader.ReadLine ()) != null)
{
if(lineNumber%2 == 0)
{
sentences.Add (lineOfText);
}
else
{
clues.Add (lineOfText);
}
lineNumber++;
}
SendMessage ("Gather");
}
示例8: ExportGrid
private void ExportGrid(string fileName, string contentType)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
Response.Charset = "";
Response.ContentType = contentType;
StringWriter sw = new StringWriter();
HtmlTextWriter HW = new HtmlTextWriter(sw);
// Read Style file (css) here and add to response
FileInfo fi = new FileInfo(Server.MapPath(".") + "\\styles\\myGrid.css");
StringBuilder sb = new StringBuilder();
StreamReader sr = fi.OpenText();
while (sr.Peek() >= 0)
{
sb.Append(sr.ReadLine());
}
sr.Close();
grid1.RenderControl(HW);
Response.Write("<html><head><style type='text/css'>" + sb.ToString() + "</style></head><body>" + sw.ToString() + "</body></html>");
Response.Flush();
Response.Close();
Response.End();
}
示例9: Button1_Click
//this is our receive button they press this to update there news
protected void Button1_Click(object sender, EventArgs e)
{
//this is where they are getting there news
const string Path = @"C:\Users\Dan the man\Desktop\news.txt";
//this is to id the path
FileInfo newsstuff = new FileInfo(Path);
//we use the following to get the data from the file
using (StreamReader sRead = newsstuff.OpenText()) {
//we have a loop that continues untill there is no more data
while (!sRead.EndOfStream)
{
//we add the items to the listbox for each line in the file
ListBox1.Items.Add(sRead.ReadLine());
//we want to only display ten so we delete once we are past that amount
if (this.ListBox1.Items.Count == 10)
{
this.ListBox1.Items.RemoveAt(1);
}
}
//this closes everything
sRead.Close();
}
}
示例10: SelectTextFile
public void SelectTextFile(string file)
{
if (file == "FirstScene") {
fileName = file;
theSourceFile = new FileInfo ("Assets/Scripts/Dialogue/FirstScene.txt");
reader = theSourceFile.OpenText ();
startText = true;
} else if (file == "Level1End") {
fileName = file;
theSourceFile = new FileInfo ("Assets/Scripts/Dialogue/Level1End.txt");
reader = theSourceFile.OpenText ();
startText = true;
} else if (file == "GoodEnding") {
fileName = file;
theSourceFile = new FileInfo ("Assets/Scripts/Dialogue/FinalDialogues/GoodEnding.txt");
reader = theSourceFile.OpenText ();
startText = true;
} else if (file == "BadEnding") {
fileName = file;
theSourceFile = new FileInfo ("Assets/Scripts/Dialogue/FinalDialogues/BadEnding.txt");
reader = theSourceFile.OpenText ();
startText = true;
} else {
theSourceFile = null;
}
}
示例11: Start
void Start()
{
triviaFile = new FileInfo(Application.dataPath + "/trivia.txt");
if (triviaFile != null && triviaFile.Exists) {
reader = triviaFile.OpenText();
} else {
embedded = (TextAsset) Resources.Load("trivia_embedded", typeof (TextAsset));
reader = new StringReader(embedded.text);
}
string lineOfText = "";
int lineNumber = 0;
while ( ( lineOfText = reader.ReadLine() ) != null ) {
string question = lineOfText;
int answerCount = Convert.ToInt32(reader.ReadLine());
List<string> answers = new List<string>();
for (int i = 0; i < answerCount; i++) {
answers.Add(reader.ReadLine());
}
Trivia temp = new Trivia(question, answerCount, answers);
triviaQuestions.Add(temp);
lineNumber++;
}
SendMessage( "BeginGame" );
}
示例12: featuretype_create
public StringBuilder featuretype_create(string featuretype_name)
{
FileInfo xmlfile = new FileInfo(HttpContext.Current.Server.MapPath("~/App_Data/featuretype.xml"));
StringBuilder sb = new StringBuilder(xmlfile.OpenText().ReadToEnd());
sb.Replace("@[email protected]", featuretype_name);
return sb;
}
示例13: Start
// Use this for initialization
void Start()
{
engine = Camera.main.GetComponent<ScriptEngine>();
originalFile = new FileInfo(Application.dataPath + "/questions.txt");
if(originalFile != null && originalFile.Exists)
{
reader = originalFile.OpenText();
}
else
{
textFile = (TextAsset)Resources.Load("embedded", typeof(TextAsset));
reader = new StringReader(textFile.text);
}
string lineOfText;
int lineNumber = 0;
while((lineOfText = reader.ReadLine()) != null)
{
if(lineNumber % 2 == 0)
{
questions.Add(lineOfText);
}
else
{
answers.Add(lineOfText);
}
lineNumber++;
}
engine.RunGame(questions, answers);
}
示例14: Parse
// this funtion reads in the file that you designate, and parses it in appropriately.
public bool Parse()
{
properties = new List<string> ();
allData = new List<ProbData> ();
FileInfo file = new FileInfo (filename);
if (file.Exists)
{
StreamReader reader = file.OpenText ();
string currLine;
string[] foundProps;
currLine = reader.ReadLine ();
foundProps = currLine.Split ('\t');
for(int ii = 0; ii < foundProps.Length - 1; ii++)
{
properties.Add(foundProps[ii]);
}
float lastIndex = 0;
while(!reader.EndOfStream)
{
currLine = reader.ReadLine();
string[] data;
data = currLine.Split('\t');
ProbData newObj = new ProbData(data.Length - 1);
for(int xx = 0; xx < data.Length -1; xx++)
{
newObj.properties.Set (xx, (data[xx].ToUpper ().CompareTo("Y") == 0));
}
float prob = float.Parse (data[data.Length - 1]);
prob += lastIndex;
lastIndex = prob;
newObj.probabilityCap = prob;
allData.Add (newObj);
print (newObj.ToString());
}
allData = allData.OrderBy(i => i.probabilityCap).ToList();
print ("Parsing Complete");
return true;
}
else
{
print ("File Not Found! " + file.FullName);
}
return false;
}
示例15: ImportLevel
public void ImportLevel(string pLevelName)
{
FileInfo levelReadingData = new FileInfo(Application.dataPath + "/" + FindLevel(pLevelName));
reader = levelReadingData.OpenText();
string input = reader.ReadToEnd();
reader.Close();
File.WriteAllText(Application.dataPath + "/waypoints.txt", input);
}