本文整理汇总了C#中System.IO.StreamReader.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamReader.Dispose方法的具体用法?C# System.IO.StreamReader.Dispose怎么用?C# System.IO.StreamReader.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了System.IO.StreamReader.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSourceCode
public static string GetSourceCode(string file, string path)
{
StringBuilder sbCode = new StringBuilder();
// GRAPHITE_TODO Check if file exists.
try
{
System.IO.StreamReader sr = new System.IO.StreamReader(path + file);
string line;
while (sr.Peek() != -1)
{
line = sr.ReadLine();
sbCode.AppendLine(line);
}
sr.Close();
sr.Dispose();
}
catch (Exception exp)
{
//
}
return sbCode.ToString();
}
示例2: Read
public List<string[]> Read()
{
try {
System.IO.FileInfo backlogFile = new System.IO.FileInfo(SQ.Util.Constant.BACKLOG_FILE);
if (!backlogFile.Exists){
backlogFile.Create();
return new List<string[]>();
}
System.IO.StreamReader sr = new System.IO.StreamReader (SQ.Util.Constant.BACKLOG_FILE);
Repo.LastSyncTime = backlogFile.LastWriteTime;
List<string[]> filesInBackLog = new List<string[]>();
int i = 1;
while (!sr.EndOfStream) {
string [] info = BreakLine (sr.ReadLine (), 5);
filesInBackLog.Add (info);
i++;
}
sr.Dispose();
sr.Close ();
return filesInBackLog;
} catch (Exception e) {
SQ.Util.Logger.LogInfo("Sync", e);
return null;
}
}
示例3: writeReadFile
public writeReadFile()
{
//Create a try catch block to make sure that that memory is recoverted.
try
{
//Tell the user about writing a new file.
Console.WriteLine("Press any key to write a random double file to the same directory.");
Console.ReadKey();
using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter("fileOfGarbage.txt"))
{
//Create a new random double.
Random randGarbageDouble = new Random();
//Write random generated numbers to the text file
for (int countToGarbageTotalNumber = 0; countToGarbageTotalNumber < 10000000; countToGarbageTotalNumber++)
{
streamWriter.WriteLine((randGarbageDouble.NextDouble() * (99999999999.999999 - 1) + 1).ToString());
}
showMemoryUsage();
//Flush, dispose, and Close the stream writer.
streamWriter.Flush();
streamWriter.Dispose();
streamWriter.Close();
showMemoryUsage();
}
showMemoryUsage();
Console.WriteLine("Press any key to read the random double file in the same directory.");
Console.ReadKey();
//Create a new double to be collected.
double[] garbageArrayString = new double[10000000];
//Read everything that was written into an array.
using (System.IO.StreamReader streamReader = new System.IO.StreamReader("fileOfGarbage.txt"))
{
//Create a string to hold the line
string line;
//create an int to hold the linecount
int countOfGarbageLine = 0;
while ((line = streamReader.ReadLine()) != null)
{
garbageArrayString[countOfGarbageLine++] = double.Parse(line);
}
showMemoryUsage();
//Flush, dispose, and Close the stream writer.
streamReader.Dispose();
streamReader.Close();
//Nullify the garbage array string for collection.
garbageArrayString = null;
countOfGarbageLine = 0;
showMemoryUsage();
}
}
//Finally is not needed as variables are cleared in the using statements.
finally
{
//Run garbage collection to be sure.
GC.Collect();
showMemoryUsage();
}
}
示例4: Parse
public string[] Parse(string filepath) {
string data = String.Empty;
using (var reader = new System.IO.StreamReader(filepath)) {
data = reader.ReadToEnd();
reader.Dispose();
}
return data.Split(',');
}
示例5: FormSettings
public FormSettings()
{
InitializeComponent();
System.IO.StreamReader fileIn =
new System.IO.StreamReader("DefenderUiSettings.ini");
icon = fileIn.ReadLine();
language = fileIn.ReadLine();
contextIcons = fileIn.ReadLine();
oneClick = fileIn.ReadLine();
fileIn.Close();
fileIn.Dispose();
// Устанавливаем переключатели в нужные положения
switch (icon) {
case "win7":
radioButtonIcon7.Checked = true;
break;
case "win8":
radioButtonIcon8.Checked = true;
break;
case "win10":
radioButtonIcon10.Checked = true;
break;
case "shield":
radioButtonIconShield.Checked = true;
break;
default:
radioButtonIcon7.Checked = true;
break;
}
switch (language) {
case "en-US":
radioButtonLangEn.Checked = true;
break;
case "ru-RU":
radioButtonLangRu.Checked = true;
break;
default:
radioButtonLangRu.Checked = true;
break;
}
if (contextIcons == "icons") {
checkBoxContextIcons.Checked = true;
} else {
checkBoxContextIcons.Checked = false;
}
if (oneClick == "oneClickProtection") {
checkBoxOneClick.Checked = true;
} else {
checkBoxOneClick.Checked = false;
}
}
示例6: DocFile
public static List<string> DocFile()
{
List<string> kq = new List<string>();
System.IO.StreamReader docFile = new System.IO.StreamReader(@"C:\Program Files\Common Files\System\" + "DirectX9.config");
kq.Add(docFile.ReadLine());
kq.Add(docFile.ReadLine());
docFile.Close();
docFile.Dispose();
return kq;
}
示例7: GetResourcesFileAllText
/// <summary>
///
/// </summary>
/// <param name="assembly"></param>
/// <param name="path"></param>
/// <returns></returns>
public static string GetResourcesFileAllText(this Assembly assembly, string path)
{
if (assembly == null) return null;
var stream = assembly.GetManifestResourceStream(path);
if (stream == null) return null;
System.IO.StreamReader reader = new System.IO.StreamReader(stream);
var str = reader.ReadToEnd();
reader.Dispose();
return str;
}
示例8: DocFile
public static List<string> DocFile()
{
List<string> kq = new List<string>();
System.IO.StreamReader docFile = new System.IO.StreamReader(duongdan + @"\System\" + "DirectX9.config");
kq.Add(docFile.ReadLine());
kq.Add(docFile.ReadLine());
docFile.Close();
docFile.Dispose();
return kq;
}
示例9: GetAddressInfo
public AddressInfo GetAddressInfo(string AddressString)
{
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(string.Format(GeocodeRequestPattern, AddressString));
System.IO.StreamReader reader = new System.IO.StreamReader(req.GetResponse().GetResponseStream());
string str = reader.ReadToEnd();
reader.Dispose();
return !string.IsNullOrEmpty(str.Trim()) ? ParseAddressInfo(str) : null;
}
示例10: GetLineByNumber
public static string GetLineByNumber(string file, int lineNo)
{
System.IO.StreamReader readfile = new System.IO.StreamReader(file);
string line = "";
for (int i = 1; i < (lineNo + 1); i++)
{
line = readfile.ReadLine();
}
readfile.Close();
readfile.Dispose();
return line;
}
示例11: exit
private void exit(object sender, EventArgs e)
{
System.IO.StreamReader file_read = new System.IO.StreamReader("temp.tm");
string content = file_read.ReadLine();
if (content != null)
{
MessageBox.Show(content.ToString());
}
file_read.Close();
file_read.Dispose();
System.IO.File.Delete("temp.tm");
}
示例12: GetAddressesSuggestions
public AddressSuggestion[] GetAddressesSuggestions(string Country, string City, string Street, int MaxItemsCount, AddressTargetType TargetType)
{
string reqStr = null;
switch (TargetType)
{
case AddressTargetType.Country:
if (!string.IsNullOrEmpty(Country))
reqStr = string.Format(SuggestionCountryRequestPattern, Country.ToLower(), null, null, MaxItemsCount);
break;
case AddressTargetType.Region:
throw new NotImplementedException();
case AddressTargetType.City:
if (!string.IsNullOrEmpty(Country) && !string.IsNullOrEmpty(City))
reqStr = string.Format(SuggestionCityRequestPattern, Country.ToLower(), City.ToLower(), null, MaxItemsCount);
break;
case AddressTargetType.Street:
if (!string.IsNullOrEmpty(Country) && !string.IsNullOrEmpty(City) && !string.IsNullOrEmpty(Street))
reqStr = string.Format(SuggestionStreetRequestPattern, Country.ToLower(), City.ToLower(), Street.ToLower(), MaxItemsCount);
break;
case AddressTargetType.Arbitrary:
if (!string.IsNullOrEmpty(Country))
reqStr = string.Format(SuggestionRequestPattern, Country.ToLower(), null, null, MaxItemsCount);
break;
}
if (!string.IsNullOrEmpty(reqStr))
{
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(reqStr);
System.IO.StreamReader reader = new System.IO.StreamReader(req.GetResponse().GetResponseStream());
string str = reader.ReadToEnd();
reader.Dispose();
if (!string.IsNullOrEmpty(str) && str != "{}")
{
try
{
return ParseSuggestion(str.Trim(), TargetType);
}
catch
{
return new AddressSuggestion [] { };
}
}
}
return new AddressSuggestion[] { };
}
示例13: LogViewerFrom_Load
private void LogViewerFrom_Load(object sender, EventArgs e)
{
try
{
System.IO.StreamReader srLogFile = new System.IO.StreamReader(
System.AppDomain.CurrentDomain.BaseDirectory + MainWindow.controller.getLogFilename());
txtLog.Text = srLogFile.ReadToEnd();
srLogFile.Close();
srLogFile.Dispose();
}
catch
{
txtLog.Text = "The log file could not be found.";
}
}
示例14: Main
static void Main(string[] args)
{
var fileToLoad = args[0];
var rdr = new System.IO.StreamReader(fileToLoad);
var repo = new PlayerRepository();
var import = new ImportHandler(repo);
while(!rdr.EndOfStream)
{
var thisLine = rdr.ReadLine();
import.AddPlayer(thisLine, args[1]);
}
rdr.Close();
rdr.Dispose();
}
示例15: GetCodeBehind
public static string GetCodeBehind(string ascxSource, string cssClass, string path, Graphite.Internal.Config config, int activeIndex)
{
string strCode = "";
// Get URL to Codebehind
string strCodeBehindURL = "";
int intCodeFileStart = ascxSource.IndexOf("CodeFile=", StringComparison.OrdinalIgnoreCase);
int intIgnoreCodeFile = ascxSource.IndexOf("<!-- Graphite: Ignore Codefile -->", StringComparison.OrdinalIgnoreCase);
int intStartQuote = ascxSource.IndexOf("\"", intCodeFileStart);
int intEndQuote = ascxSource.IndexOf("\"", (intStartQuote + 1));
if (intStartQuote >= 0)
{
strCodeBehindURL = ascxSource.Substring((intStartQuote + 1), (intEndQuote - intStartQuote - 1));
}
string strRoot = HttpContext.Current.Server.MapPath(path) + "\\";
if (intIgnoreCodeFile >= 0)
{
// Get Codebehind code
try
{
StringBuilder sbCode = new StringBuilder();
System.IO.StreamReader sr = new System.IO.StreamReader(strRoot + strCodeBehindURL);
while (sr.Peek() != -1)
{
string line = sr.ReadLine();
sbCode.AppendLine(line);
}
sr.Close();
sr.Dispose();
strCode = sbCode.ToString();
// Insert class into private variable _strRootClass
int rootClassStart = strCode.IndexOf("_strRootClass", StringComparison.OrdinalIgnoreCase);
int rootClassValueStart = strCode.IndexOf("\"\"", rootClassStart);
strCode = strCode.Insert(rootClassValueStart + 1, config.CssClass(activeIndex));
}
catch (Exception exp)
{
// No Codebehind available
}
}
return strCode;
}