A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 颜晓峰 中级黑马   /  2013-3-6 12:01  /  1660 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 颜晓峰 于 2013-3-11 14:35 编辑

我想将一个保存着用户信息的字符串:
string user="用户信息:xxxxxxxxxxxxxxxxxxxxxxx"
保存到本地的txt文件中,以便下次调用。

请问要用什么方法?需要调用什么命名空间?

评分

参与人数 1技术分 +1 收起 理由
张文 + 1

查看全部评分

3 个回复

倒序浏览
调用一下 System.IO.File.WriteAllText()方法就可以了。 具体传什么参数 自己看文档注释
回复 使用道具 举报
filestream  数据流  StreamWriter快速写入文本文件
也可以File.WriteAllText(“path”, “string”);将字符串全部写入文件

评分

参与人数 1技术分 +1 收起 理由
张文 + 1

查看全部评分

回复 使用道具 举报
  1. static void Main(string[] args)
  2.         {
  3.                 Console.WriteLine("请输入内容:");
  4.                 string str = Console.ReadLine();
  5.                 using (StreamWriter sw = new StreamWriter(@"d:\test.txt"))
  6.                 {
  7.                     sw.WriteLine(str);
  8.                     Console.WriteLine(@"已存入D:\test.txt。");
  9.                 }
  10.                 Console.ReadKey();
  11.         }
复制代码
因为路径里有“\”的的存在,所以用了“@”来忽略转义符。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马