最近做的项目用到了很多读写文本的东西,在这里把它复制上来备用,有的也是从网上拿来的嘿嘿:
void outputHtml(string content,string link , StreamWriter sw,string filePathDir)
{
StreamWriter sw;
if (File.Exists(@"D:\test\333.html"))
{
File.Delete(@"D:\test\333.html");
}
sw = File.CreateText(@"D:\test\333.html");
sw.WriteLine("<p><span class=\"STYLE9\">"+link+"</span><br />");
sw.WriteLine("<p><span class=\"STYLE10\">"+content+"</span><br />");
sw.WriteLine("<p><span class=\"STYLE11\">" + "保存路径: "+filePathDir + "</span></p>");
sw.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string path = "Program Files\\TestWinCE\\configPIO.txt";
using (StreamReader sr = File.OpenText(path))
{
string s = " ";
s = sr.ReadLine();
textBox1.Text = s;
sr.Close();
}
}
//测试写入
private void outputHtml()
{
StreamWriter sw;
if (File.Exists("\\Windows\\333.txt"))
{
File.Delete("\\Windows\\333.txt");
}
sw = File.CreateText("\\Windows\\333.txt");
sw.WriteLine("sssss");
sw.WriteLine("vdfg");
sw.Close();
}
http://blog.163.com/jp317jay@126/blog/static/8859828520097505624947/ 读写文本
private void writeTxt(string fullName)
{
StreamWriter sr;
if (File.Exists(fullName)) //如果文件存在,则创建File.AppendText对象
{
sr = File.AppendText(FILE_NAME);
}
else //如果文件不存在,则创建File.CreateText对象
{
sr = File.CreateText(fullName);
}
sr.WriteLine(str);
sr.Close();
}
string apppath = Assembly.GetExecutingAssembly().GetName().CodeBase;
apppath = Path.GetDirectoryName(apppath);
string ss= Path.Combine(apppath, "address.txt");
MessageBox.Show(ss);
判断combox 添加选项两种方法
String sURL = Convert.ToString(e.Url);
bool IsAdd = false;
for (int i = 0; i < this.txturl.Items.Count; i++)
{
if (sURL.Equals((String)this.txturl.Items[i]))
{ IsAdd = true; break; }
}
if (!IsAdd)
{
this.txturl.Items.Add(sURL);
}
/*
int index = txturl.FindStringExact(sURL);
if (e.Url == webBrowser1.Document.Url)
if (index == -1)
{
txturl.Items.Add(sURL);
txturl.SelectedIndex = txturl.FindStringExact(sURL);
}
else
{
txturl.SelectedIndex = index;
}
*/
启动 相应程序的代码
ProcessStartInfo startInfo = new ProcessStartInfo(listFileFounded.SelectedItem.ToString(), null);
Process.Start(startInfo);
public static string GetApplicationPath()
{
System.Reflection.Module[] modules = System.Reflection.Assembly.GetExecutingAssembly().GetModules();
string aPath = System.IO.Path.GetDirectoryName(modules[0].FullyQualifiedName);
if ((aPath != "") && (aPath[aPath.Length - 1] != '\\'))
aPath += '\\';
return aPath;
}
在WinCE下,不能用相对路径,必须用绝对路径(Full Path) 来定位文件。
如,在Program Files\TestProgram目录下的abc.txt文件,只能用
Program Files\TestProgram\abc.txt来定位,而不能用abc.txt定位。
如:
private void button1_Click(object sender, EventArgs e)
{
string path = "Program Files\\TestWinCE\\configPIO.txt";
using (StreamReader sr = File.OpenText(path))
{
string s = " ";
s = sr.ReadLine();
textBox1.Text = s;
sr.Close();
}
}
与Windows NT不一样,Windows CE没有当前目录这个概念,因此,任何路径只是相对于根目录而言的。如果你的软件给文件或目录使用相对路径,那么你很可能把它们移到别的地方了。例如,路径".\abc"在Windows CE中被当作"\abc"看待。http://www.cnblogs.com/buffer/archive/2009/04/13/1434748.html
找到了,呵呵
TCHAR szFileName[256] = {0};
DWORD dwNameLen = ::GetModuleFileName(NULL,szFileName,256);
if(dwNameLen == 0)
{
// Error process
}
//szFileName is Like "\directory\filename.ex
m_Caption.SetText(szFileName);
转自网上的方法
方法1:
Directory.GetCurrentDirectory()。
这个方法只能在.NET的完整版中使用,NETCF中不支持该功能,调用时会引发异常。
方法2:
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)。
这个方法是MSDN中给出的针对NETCF平台的,当在PC的NET完整版中获取到的路径中测试时,发现最终的路径中带有file:前缀,如file:\c:\debug,一般情况下我们并不需要这个前缀,可以手动将其去掉。
方法3:
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName).
该方法也是针对NETCF给出的解决方案,当在PC的NET完整版测试中可以获取到一致的结果。
小结:
如果考虑到代码在PC和PDA上的兼容性,则建议使用第三种方法。第一种方法是万万不行的,而且第一种方式获取到的路径也并不一定就是真正的应用程序所在的路径。
http://www.cnblogs.com/sail/archive/0001/01/01/1521992.html
http://blog.sina.com.cn/s/blog_4d91c1660100fpcu.html
http://hi.baidu.com/372590721/blog/item/c3c17f2b1ad40a3f5243c146.html
http://zhidao.baidu.com/question/48190857.html读写 txt文件
http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
http://ncny.hljagri.gov.cn/syjs/004.htm
分享到:
相关推荐
VC++读写文本文件txt,提供了大量的读写文本文件txt源代码,适合初级VC人员的操作
JAVA简单的读写文本文件的代码JAVA简单的读写文本文件的代码
本人利用VB.NET中FileOpen()函数编写对文本文件的逐行写入和逐行读取的小程序,而且写的文本没有双引号,很实用的
用C#读写文本文件,用C#读写文本文件,用C#读写文本文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; ...namespace Example_WriteTest ... Console.WriteLine("请输入创建的文件名,输入正确的路径");...
提供了Python读写文本和读写excel的代码。Python拥有丰富且优质量的库,这些库涉及游戏开发,科学计算,数据库接口,网络脚本编程,资源提供等各个方面。 *资源库:PYPl ——拥有超过85000个Python模块和脚本,这些...
C#读写文本文件(不会产生乱码)[初学者用]
c++读写文本文件,实现对文件的读和取操作,用到了fstream流的概念。
Delphi直接读写文本文件的方法,不通过Memo控件,直接将字符串写入文件,或者从文件中读出来。很使用
源代码:读写文本,把文本当数据库使用,谢谢各位使用。
C#读写文本文件的源码,可以逐行读出,也介绍了全部读出的方法.程序简洁易懂.
主要介绍了使用Python读写文本文件及编写简单的文本编辑器的方法,可以利用简单的Python代码实现编辑器中的读取清空和文本文件的新建等操作,需要的朋友可以参考下
Java读写文本文件的示例代码 这个例子可以帮助JAVA爱好者理解JAVA对文件的操作,打开、删除、写入等操作。对初学者很有帮助。
用JS文件去读写文本文件,根据自己需求使用,本人测试可以使用
如何以行为单位读写文本文件
Java IO基础之读写文本文件
Java读写文本文件的示例代码.7z
好久没给大家分享Delphi源代码了,这里给大家一个delphi读写txt和ini的实例,通过Memo读写文本文件和ini文件源码
Java读写文本文件的示例代码.rar