请问怎样把一个数值保存到TXT文本里边去 public void GetPag(int getId) { tagId = getId; } 取出来的这个 tagId 值,保存到txt 文本里边取名叫 text.txt然后怎么在把这个值取出来。。希望大神能帮忙。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 StreamWriter writer = new StreamWriter()---写StreamReader sr = new StreamReader()----读 using system.io参考 openFileDialog1.Filter = "文本文件(*.txt)|*.txt";openFileDialog1.ShowDialog();textBox1.Text=openFileDialog1.FileName;StreamReader SR=new StreamReader(textBox1.Text,Encoding.Default);textBox2.Text=SR.ReadLine(); System.IO.File.WriteAllText("text.txt",tagId.ToString()); 写StreamWriter sw = File.AppendText(txtFilePath); sw.WriteLine("test");sw.Flush();sw.Close(); 读 StreamReader fileStream = new StreamReader(txtFilePath,Encoding.Default); txtContent.Text = fileStream.ReadToEnd(); StreamWriter w = new StreamWrited(sPath);w.WriteLine(i.tostring());w.close(); //存储的文件名 private const string SettingFileName = "\text.txt"; /// <summary> /// 保存配置 /// </summary> /// <param name="tagId">保存的值 tagId</param> /// <param name="appPath">存放的路径</param> public static void SaveSetting(string tagId, string appPath) { try { string fullName = appPath + SettingFileName; if (!Directory.Exists(appPath)) Directory.CreateDirectory(appPath); if (!File.Exists(fullName)) { FileStream fs = File.Create(fullName); fs.Close(); } StreamWriter sw = new StreamWriter(fullName, false); sw.WriteLine(tagId); sw.Close(); } catch { } } /// <summary> /// 获得配置文件的信息 /// </summary> /// <param name="appPath">文件所在位置</param> /// <returns></returns> public static string GetSetting(string appPath) { string tagId = string.Empty; try { string fullName = appPath + SettingFileName; if (!Directory.Exists(appPath)) Directory.CreateDirectory(appPath); if (!File.Exists(fullName)) { FileStream fs = File.Create(fullName); fs.Close(); } StreamReader sr = new StreamReader(fullName); while (!sr.EndOfStream) { string strLine = sr.ReadLine(); if (strLine != "") { tagId = strLine; } } sr.Close(); } catch { } return tagId; } socket服务端的错误,帮忙看看. 求一SQL语句,高手请进。 DataGridView控件获取当前行(排序) 如何复制文件 請教datagrid的問題,同時使用兩個為什麼一個功能不全啊? 简单问题:Program.cs中try...catch语句有问题~ 求一存储过程,已经超出了我的智利范围 高分请教中间层的实现??? 在C#中的重载是不是只有在基类方法是virtual的情况下才行? 请问如何在网上打印报表? winform 中mouseEnter和mouseLeave事件 C# 按 ,将字符串分割成片段 片段们存入字符串数组中
StreamReader sr = new StreamReader()----读
using system.io
参考
openFileDialog1.ShowDialog();
textBox1.Text=openFileDialog1.FileName;
StreamReader SR=new StreamReader(textBox1.Text,Encoding.Default);
textBox2.Text=SR.ReadLine();
StreamWriter sw = File.AppendText(txtFilePath);
sw.WriteLine("test");
sw.Flush();
sw.Close(); 读
StreamReader fileStream = new StreamReader(txtFilePath,Encoding.Default);
txtContent.Text = fileStream.ReadToEnd();
w.WriteLine(i.tostring());
w.close();
private const string SettingFileName = "\text.txt"; /// <summary>
/// 保存配置
/// </summary>
/// <param name="tagId">保存的值 tagId</param>
/// <param name="appPath">存放的路径</param>
public static void SaveSetting(string tagId, string appPath)
{
try
{
string fullName = appPath + SettingFileName;
if (!Directory.Exists(appPath))
Directory.CreateDirectory(appPath);
if (!File.Exists(fullName))
{
FileStream fs = File.Create(fullName);
fs.Close();
}
StreamWriter sw = new StreamWriter(fullName, false);
sw.WriteLine(tagId);
sw.Close();
}
catch { }
}
/// <summary>
/// 获得配置文件的信息
/// </summary>
/// <param name="appPath">文件所在位置</param>
/// <returns></returns>
public static string GetSetting(string appPath)
{
string tagId = string.Empty;
try
{
string fullName = appPath + SettingFileName;
if (!Directory.Exists(appPath))
Directory.CreateDirectory(appPath);
if (!File.Exists(fullName))
{
FileStream fs = File.Create(fullName);
fs.Close();
}
StreamReader sr = new StreamReader(fullName);
while (!sr.EndOfStream)
{
string strLine = sr.ReadLine();
if (strLine != "")
{
tagId = strLine;
}
}
sr.Close();
}
catch { }
return tagId;
}