最简单的:

--------写
//content是要写入文本的字符串
//(@txtPath + @"\" + rid + ".txt");要被写入的TXT
StreamWriter sw = new StreamWriter(@txtPath + @"\" + rid + ".txt");
sw.WriteLine(content);
sw.Close();
---------读
//folder被读取的文件路径
text = File.ReadAllText(folder, System.Text.Encoding.GetEncoding("gb2312")); -------写入流
//将string写入文件
try
{
FileStream fs = new FileStream(@"d:\数据处理\法规20080116HTML\" + Actid.ToString() + ".html", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs,System.Text.Encoding.GetEncoding("gb2312"));
sw.Flush();
sw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.Write(pageContent);
sw.Close();
}
catch (Exception ex) { }
//HTTP向应后写出文件 HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
WebResponse result = null;
try
{
myWebRequest = (HttpWebRequest)WebRequest.Create(Url);
result = myWebRequest.GetResponse();
Stream response = result.GetResponseStream();
byte[] bytes = new byte[10240];
int n = 1; FileStream fs = File.Create(@"d:\数据处理\法规20080116HTML\" + Actid.ToString() + ".html");
while (n > 0)
{
n = response.Read(bytes, 0, 10240);
fs.Write(bytes, 0, n);
}
response.Close();
fs.Close();
}
catch (Exception ex) { } //读取 string FileContent = File.ReadAllText(path, System.Text.Encoding.GetEncoding("gb2312"));

  

最新文章

  1. JavaScript中String对象的方法介绍
  2. Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file
  3. php获取本周和上周的开始日期和结束日期
  4. OpenGL函数解析之glLoadIdentity()
  5. Java中HashMap,LinkedHashMap,TreeMap的区别[转]
  6. javascript-权威指南读书笔记(1)
  7. .NET代码编写规范 整理
  8. 轻松使用px为单位开发移动端页面
  9. Vessels
  10. Sublime 学习记录(二) package control 组件
  11. Unity编程标准导引-Unity中的基本概念-2.1界面概览
  12. [再寄小读者之数学篇](2014-06-22 积分不等式 [中国科学技术大学2012年高等数学B考研试题])
  13. jmeter 连接数据库测试笔记
  14. icpc2018-焦作-F Honeycomb bfs
  15. python - 6. Defining Functions
  16. java 构造json对象数组
  17. vue 请求后台数据2(copy)
  18. Android Studio:正确导入SO相关文件
  19. Telnet 协议详解
  20. 2 字节的 UTF-8 序列的字节 2 无效 解决方法

热门文章

  1. 火车票问题.以及x轴连续矩形,最大面积问题
  2. Dcloud课程8 开心一刻应用如何实现
  3. http 协议上传文件multipart form-data boundary 说明--转载
  4. android notify
  5. 免费的EmBitz可替代Keil MDK开发STM32、NXP项目
  6. DTU(用于将串口数据转换为IP数据或将IP数据转换为串口数据通过无线通信网络进行传送的无线终端设备)
  7. C# Unity依赖注入利用Attribute实现AOP功能
  8. C# winform利用反射和自定义特性加载功能模块(插件式开发)
  9. Android学习之图片压缩,压缩程度高且失真度小
  10. ORA-00957: 反复的列名