本文整理汇总了C#中System.IO.StreamReader.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamReader.Peek方法的具体用法?C# System.IO.StreamReader.Peek怎么用?C# System.IO.StreamReader.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了System.IO.StreamReader.Peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: insertCountries
static void insertCountries()
{
MySqlCommand cmd = new MySqlCommand("INSERT INTO `climate`.`countries` (`abbreviation`,`name`) VALUES (@abbrev,@name);", conn);
conn.Open();
System.IO.StreamReader countries = new System.IO.StreamReader("Y:\\country-list.txt");
System.IO.StreamWriter csvCountries = new System.IO.StreamWriter("Y:\\country-list.csv");
Console.WriteLine(countries.ReadLine());
Console.WriteLine(countries.ReadLine());
while (countries.Peek() > 0)
{
string line = countries.ReadLine();
string[] strings = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
//string[] strings = line.Split(new char[] { ' ' }, 12);
Console.WriteLine(strings[0] + "," + strings[1]);
csvCountries.WriteLine(strings[0] + "," + strings[1]);
cmd.Parameters.AddWithValue("abbrev", strings[0]);
cmd.Parameters.AddWithValue("name", strings[1]);
cmd.ExecuteScalar();
cmd.Parameters.Clear();
}
conn.Close();
csvCountries.Close();
countries.Close();
}
示例2: GetSourceCode
// Returns source code of a demo file
public static string GetSourceCode(string suffix, bool dicFiles, int intActiveIndex, string path, Graphite.Internal.Config config)
{
string strFileName = "default";
if (dicFiles == false)
{
int intMenuItemActive = intActiveIndex;
strFileName = config.Type(intMenuItemActive);
}
string strRoot = HttpContext.Current.Server.MapPath(path) + "\\";
StringBuilder sbCode = new StringBuilder();
try
{
System.IO.StreamReader sr = new System.IO.StreamReader(strRoot + strFileName + suffix);
string line;
while (sr.Peek() != -1)
{
line = sr.ReadLine();
sbCode.AppendLine(line);
}
sr.Close();
sr.Dispose();
}
catch (Exception exp)
{
//
}
return sbCode.ToString();
}
示例3: 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();
}
示例4: CreateRegex
static Regex lineSimpleApply = CreateRegex(@"^Ext.apply\(\s*(?<name>({id}\.)?{idx})(\.prototype)?.*"); // e.g. Ext.apply(Dextop.common, {
#endregion Fields
#region Methods
public override void ProcessFile(String filePath, Dictionary<String, LocalizableEntity> map)
{
ClasslikeEntity jsObject = null;
System.IO.TextReader reader = new System.IO.StreamReader(filePath, Encoding.UTF8);
//Logger.LogFormat("Processing file {0}", filePath);
try
{
while (reader.Peek() > 0)
{
String line = reader.ReadLine();
ClasslikeEntity o = ProcessExtendLine(filePath, line);
if (o != null)
jsObject = o;
else if (jsObject != null) {
LocalizableEntity prop = ProcessPropertyLine(jsObject, line);
if (prop != null && !map.ContainsKey(prop.FullEntityPath))
map.Add(prop.FullEntityPath, prop);
}
}
Logger.LogFormat("Processing file {0} - Success", filePath);
}
catch (Exception ex)
{
Logger.LogFormat("Processing file {0} - Error", filePath);
throw ex;
}
finally
{
reader.Close();
}
}
示例5: fetchDataToolStripMenuItem_Click
private void fetchDataToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Collections.Generic.List<string> SYMBOLS = new System.Collections.Generic.List<string>();
try
{
string path = null;
string dest = null;
using (System.IO.StreamReader SR = new System.IO.StreamReader(String.Concat(System.IO.Directory.GetCurrentDirectory(), "\\tickers.txt")))
{
while (SR.Peek() > 0)
{
SYMBOLS.Add(SR.ReadLine());
}
SR.Close();
}
WebClient Client = new WebClient();
foreach (string ticker in SYMBOLS)
{
//MessageBox.Show(ticker);
// Format
// Date Open High Low Close Volume AdjClose
int[] DateVals = GetLatest(ticker);
// foreach ticker get data
// http://real-chart.finance.yahoo.com/table.csv?s=AAPL&a=11&b=12&c=1980&d=06&e=6&f=2014&g=d&ignore=.csv
// Date testing with 7/29/2014
path = "http://real-chart.finance.yahoo.com/table.csv?s=" + ticker + "&a=" + DateVals[0].ToString() + "&b=" + DateVals[1] + "&c=" + DateVals[2] + "&d=06&e=29&f=2014&g=d&ignore=.csv";
//MessageBox.Show(path);
dest = System.IO.Directory.GetCurrentDirectory() + "\\temp\\test.csv";
// Download data into data set then add to file?
Client.DownloadFile(path, dest);
using (System.IO.StreamReader SR = new System.IO.StreamReader(dest))
{
while (SR.Peek() > 0)
{
MessageBox.Show(SR.ReadLine());
}
SR.Close();
}
}
}
catch (Exception err)
{
System.Windows.Forms.MessageBox.Show("Reading \'Tickers.txt\' failed: \n\n" + err.ToString());
}
}
示例6: insertStations
static void insertStations()
{
MySqlCommand cmd = new MySqlCommand("INSERT INTO `climate`.`stations` (`USAF`,`WBAN`,`station`,`country`,`FIPS`,`state`,`call`,`latitude`,`longitude`,`elevation`) "
+ "VALUES (@usaf,@wban,@station,@country,@fips,@state,@call,@lat,@lon,@elev);", conn);
conn.Open();
System.IO.StreamReader stations = new System.IO.StreamReader("Y:\\ish-history.csv");
Console.WriteLine(stations.ReadLine());
while (stations.Peek() > 0)
{
string line = stations.ReadLine();
string[] strings = line.Split(new char[] { ',' }, 12);
for(int i = 0; i<10; i++)
{
strings[i] = strings[i].Replace("\"", string.Empty);
}
int c = Convert.ToInt32(strings[0]);
if (c > 61240)
{
//Console.WriteLine(strings[0] + "," + strings[1]+","+strings[2]+","+strings[3]+","+strings[4]+","+strings[5]+","+strings[6]+","+strings[7]+","+strings[8]+","+strings[9]);
cmd.Parameters.AddWithValue("usaf", strings[0]);
cmd.Parameters.AddWithValue("wban", strings[1]);
cmd.Parameters.AddWithValue("station", strings[2]);
cmd.Parameters.AddWithValue("country", strings[3]);
cmd.Parameters.AddWithValue("fips", strings[4]);
cmd.Parameters.AddWithValue("state", strings[5]);
cmd.Parameters.AddWithValue("call", strings[6]);
cmd.Parameters.AddWithValue("lat", strings[7]);
cmd.Parameters.AddWithValue("lon", strings[8]);
cmd.Parameters.AddWithValue("elev", strings[9]);
try
{
cmd.ExecuteScalar();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
cmd.Parameters.Clear();
}
Console.WriteLine(strings[0]);
}
conn.Close();
stations.Close();
}
示例7: LoadBMSFile
private void LoadBMSFile()
{
IsLoading = true;
System.IO.StreamReader sr
= new System.IO.StreamReader(Path, System.Text.Encoding.Default);
string result = string.Empty;
while(sr.Peek() >= 0)
{
string buffer = sr.ReadLine();
System.Console.WriteLine(buffer);
result += buffer + System.Environment.NewLine;
}
sr.Close();
}
示例8: Parse
public static XMLDocument Parse(System.IO.Stream ins, XMLListener l)
{
StringBuilder sbr = new StringBuilder();
try
{
int i = 0;
while (ins.Length == 0)
{
i++;
try
{
Thread.Sleep(100L);
}
catch
{
}
if (i <= 100)
{
continue;
}
throw new System.Exception("Parser: InputStream timed out !");
}
using (System.IO.StreamReader reader = new System.IO.StreamReader(ins, System.Text.Encoding.UTF8))
{
while (reader.Peek() > -1)
{
sbr.Append(reader.ReadLine());
sbr.Append("\n");
}
if (reader != null)
{
reader.Close();
}
}
}
catch (System.Exception ex)
{
Log.Exception(ex);
}
finally
{
if (ins != null)
{
ins.Close();
ins = null;
}
}
return new XMLParser().ParseText(sbr.ToString(), l);
}
示例9: LoadSettings
public void LoadSettings()
{
s_file = new System.IO.FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\settings.dat", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
using (System.IO.StreamReader sR = new System.IO.StreamReader(s_file))
{
while (sR.Peek() != -1)
{
string s = sR.ReadLine();
if (s != null)
s_settings.Add(s.Substring(0, s.IndexOf(":", StringComparison.Ordinal)), s.Substring(s.IndexOf(":", StringComparison.Ordinal) + 1));
}
}
s_file = new System.IO.FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\settings.dat", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
}
示例10: Upload
public ActionResult Upload(HttpPostedFileBase upload, BulkUpload model)
{
string info = "";
try {
// Check if the user has entered application ids
if (model.Applications.Trim().Length > 0)
{
string[] appications = model.Applications.Split(';');
string[] securityRoles = model.SecurityRoles.Split(';');
string[] permissionGroups = model.PermissionGroups.Split(';');
var file = new System.IO.StreamReader(upload.InputStream);
while (file.Peek() >= 0)
{
string line = file.ReadLine();
string[] fields = line.Split(',');
var bulkUser = new BulkUser();
bulkUser.Title = fields[0];
bulkUser.GivenName = fields[1];
bulkUser.MiddleName = fields[2];
bulkUser.Surname = fields[3];
bulkUser.Email = fields[4];
bulkUser.Password = fields[5];
// call to creat user
// call
}
}
else
{
// No Application entered
info = "No Application Ids entered.";
}
}
catch (Exception exp)
{
info = exp.Message;
}
return View();
}
示例11: csvToHTML
public Boolean csvToHTML()
{
String outputfile;
if (this.InputFilePath == null)
{
return false;
}
else
{
outputfile = getRawOutputFilePath()+"_output.html";
}
System.IO.StreamReader sr = new
System.IO.StreamReader("..\\..\\gpssample.html");
System.IO.StreamReader srcsv = new System.IO.StreamReader(InputFilePath);
System.IO.StreamWriter sw = new System.IO.StreamWriter(outputfile);
String str = sr.ReadLine();
//内容を一行ずつ読み込む
while (sr.Peek() > -1)
{
sw.WriteLine(str);
if (str.IndexOf("StartArray()") != -1)
{
//ヘッダー行
String strcsv = srcsv.ReadLine();
//内容1行目
strcsv = srcsv.ReadLine();
long i = 0;
while (strcsv != null)
{
String[] contents = strcsv.Split(',');
sw.WriteLine("patharray[" + i
+ "] = new google.maps.LatLng(" + contents[1]
+ "," + contents[2] + ");");
i++;
strcsv = srcsv.ReadLine();
}
}
str = sr.ReadLine();
}
//閉じる
sw.Close();
srcsv.Close();
sr.Close();
return true;
}
示例12: 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;
}
示例13: btnOpen_Click
private void btnOpen_Click(object sender, EventArgs e)
{
String file_name = "\\test.txt"; // provides the location for our file name in this case its test.txt
String textLine = ""; // creates a textLine of string text
ArrayList findSubroutine = new ArrayList(); // Only saves the subroutines
file_name = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + file_name; // gets my specific object txt location
System.IO.StreamReader objReader; // System.IO.StreamReader creates an objReader which ill use later in the program.
objReader = new System.IO.StreamReader(file_name);
ArrayList location = new ArrayList();
string[] insructions = {"NOP", "MULS","ADD","SUB","LDI","AND","OR","RJMP","SLEEP","TST"};
string[] opcodes = {"0000000000000000","00000010","000011","000110","1110","001000","001010","1100","1001010110001000","001000"};
string test = ""; // created to test if we are able to attach opcodes from function together *which was successful*
for (int i = 0; i < opcodes.Length; i++)
{
if (opcodes[i].Count() < 16)
{
MessageBox.Show("This mother fucker has less than 16 characters " + i);
test = getOp(opcodes[i], "something", "somethingelse");
}
}
MessageBox.Show(test);
int x = 1;
while (objReader.Peek() != -1)
{
textLine = objReader.ReadLine() + "\r\n"; //reads this line by line
if (textLine.Contains(":"))
{
findSubroutine.Add(textLine);
location.Add(x);
}
x++;
}
//code just for testing location and subroutine.
for (int i = 0; i < findSubroutine.Count; i++)
{
//MessageBox.Show(findSubroutine[i].ToString());
//MessageBox.Show(location[i].ToString());
}
objReader.Close();
}
示例14: Form2
public Form2()
{
InitializeComponent();
List<string> set = new List<string>();
using (var sr = new System.IO.StreamReader("config.ini"))
{
while (sr.Peek() >= 0)
set.Add(sr.ReadLine());
}
textBox1.Text = set[0];
textBox2.Text = set[1];
textBox3.Text = set[2];
textBox4.Text = set[3];
textBox5.Text = set[4];
textBox3.Text = Decode(textBox3.Text);
}
示例15: btOk_Click
private void btOk_Click(object sender, EventArgs e)
{
webBrowser.Navigate("http://hipoqih.com");
this.Refresh();
string st_Texto = null;
string st_url = "http://hipoqih.com/leerposicion.php?iduser=" + idseguro;
//guardar los resultado
System.Net.WebRequest req = System.Net.WebRequest.Create(st_url);
req.Timeout = 10000;
System.Net.WebResponse resul = req.GetResponse();
System.IO.Stream recibir = resul.GetResponseStream();
Encoding encode = Encoding.GetEncoding("utf-8");
System.IO.StreamReader sr = new System.IO.StreamReader(recibir, encode);
// leer el estreamer
while (sr.Peek() >= 0)
{
st_Texto += sr.ReadLine();
}
resul.Close();
//ahora interpreta la cadena
// que viene asi:
// echo'latitud','longitud'
string st_lat = "";
string st_lon = "";
int i_a;
//coge el contenido devuelto por hipoqih y lo parsea
if (st_Texto != null)
{
i_a = st_Texto.IndexOf(",");
if (i_a > 0)
{
st_lat = st_Texto.Substring(0, i_a);
st_lon = st_Texto.Substring(i_a + 1, st_Texto.Length - i_a - 1);
}
}
// lo pinto en referencias
plugin_hipoqih.hipoqih.frmPreferencias.txLat.Text = st_lat;
plugin_hipoqih.hipoqih.frmPreferencias.txLon.Text = st_lon;
this.Close();
}