使用C#在.NET下读写文件!

tyc2002 2003-02-22 12:39:02
请问怎样在WindowsApplication下读写*.ini文件并写进Acess数据库?请各位大侠帮帮忙!急!!
...全文
55 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tyc2002 2003-03-05
  • 打赏
  • 举报
回复
谢谢大家!
kaimuboy 2003-02-25
  • 打赏
  • 举报
回复
关注!
tyc2002 2003-02-25
  • 打赏
  • 举报
回复
谢谢,此问题我已经基本解决,我是先写的一个类,在窗体下调用的方法来解决的。
aaxu 2003-02-24
  • 打赏
  • 举报
回复
UP
cqing 2003-02-24
  • 打赏
  • 举报
回复
当然是用API了,否则还要自己parse。
zken 2003-02-23
  • 打赏
  • 举报
回复
写入access就不用说了吧,就是数据库操作,
读取ini就是文本
using System.IO;
读取程序
string s="";
StreamReader srReadLine = new StreamReader((System.IO.Stream)File.OpenRead("e:\\a.txt"),System.Text.Encoding.Default);
StreamWriter st=new StreamWriter((System.IO.Stream)File.OpenWrite("e:\\b.txt"),System.Text.Encoding.Default);
srReadLine.BaseStream.Seek(0, SeekOrigin.Begin);
while (srReadLine.Peek() > -1)
{
s=srReadLine.ReadLine();
}
srReadLine.Close();
//Console.Read();
st.Close();

把每一行的东西读循环读入s,自己分析就可以了
76ers 2003-02-23
  • 打赏
  • 举报
回复
好像不用API也可以。
用stream就行。
cwj007 2003-02-23
  • 打赏
  • 举报
回复
关注
ylm0101 2003-02-22
  • 打赏
  • 举报
回复
用流写和读吧(using System.IO)
StreamReader sr=new StreamReader(path,System.Text.Encoding.Default );
string strSr = sr.ReadToEnd();
sr.Close();


StreamWriter writer = new StreamWriter(path);
writer.Write(strSr);
writer.Flush();
writer.Close();
用数组转化为字段,保存,
chinchy 2003-02-22
  • 打赏
  • 举报
回复
using System.Runtime.InteropServices;


//写INI文件
//lpAppName :section name
//lpKeyName :key name
//lpString : string to add
//lpFileName:initialization file
[DllImport("kernel32.dll")]
public static extern long WritePrivateProfileString(string lpAppName,string lpKeyName,string lpString,string lpFileName);
//读INI文件
//lpAppName :section name
//lpKeyName :key name
//lpDefault :default string
//lpReturnedString:destination buffer
//nSize :size of destination buffer
//lpFileName :initialization file name
[DllImport("kernel32.dll")]
public static extern int GetPrivateProfileString(string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName);


System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

WritePrivateProfileString("Mail","Address","xxx@xxx.com","D:\\WIN.INI");
int i=GetPrivateProfileString("Mail","Address","",temp,255,"D:\\WIN.INI");
MessageBox.Show(temp.ToString());

yarshray 2003-02-22
  • 打赏
  • 举报
回复
读写INI必须使用API

具体方法如下:
http://www.zdnet.com.cn/developer/code/story/0,2000081534,39065664-1,00.htm

至于写入数据库,建立一张表,然后写到dataset然后通过dataAdapter更新

就可以了.

111,119

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧