C#通过流写入数据到文件的方法
本文实例讲述了C#通过流写入数据到文件的方法。分享给大家供大家参考。具体实现方法如下:
using System;
using System.IO;
public class WriteFileStuff {
public static void Main() {
FileStream fs = new FileStream("c:\\tmp\\WriteFileStuff.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
try {
sw.WriteLine("Howdy World.");
} finally {
if(sw != null) { sw.Close(); }
}
}
}
希望本文所述对大家的C#程序设计有所帮助。
相关推荐
-
C#实现文件与二进制互转并存入数据库
//这个方法是浏览文件对象 private void button1_Click(object sender, EventArgs e) { //用户打开文件浏览 using (OpenFileDialog dialog = new OpenFileDialog()) { //只能单选一个文件 dialog.Multiselect = false; //选择一个文件 if (dialog.ShowDialog() == DialogResult.OK) { try { //把选择的文件路径给tx
-
c# 以二进制读取文本文件
复制代码 代码如下: using System; using System.IO; public class FileApp { public static void Main() { // 在当前目录创建一个文件myfile.txt,对该文件具有读写权限 FileStream fsMyfile = new FileStream("myfile.txt" , FileMode.Create, FileAccess.ReadWrite);
-
C#文件和字节流的转换方法
本文实例讲述了C#文件和字节流的转换方法.分享给大家供大家参考.具体实现方法如下: 1.读取文件,并转换为字节流 FileStream fs = new FileStream(filename,FileMode.Open,FileAccess.Read); byte[] infbytes = new byte[(int)fs.Length]; fs.Read(infbytes, 0, infbytes.Length); fs.Close(); return infbytes; 2.将字节流写入文
-
C#使用文件流读取文件的方法
本文实例讲述了C#使用文件流读取文件的方法.分享给大家供大家参考.具体如下: using System; using System.IO; namespace Client.Chapter_11___File_and_Streams { public class OpenExistingFile { static void Main(string[] args) { FileInfo MyFile = new FileInfo(@"c:\Projects\Testing.txt");
-
C#生成PDF文件流
本文实例为大家分享了C#生成PDF文件流的具体代码,供大家参考,具体内容如下 1.设置字体 static BaseFont FontBase = BaseFont.CreateFont("C:\\WINDOWS\\FONTS\\STSONG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); static iTextSharp.text.Font bodyFont = new iTextSharp.text.Font(FontBase, 12)
-
C#远程获取图片文件流的方法
本文实例讲述了C#远程获取图片文件流的方法.分享给大家供大家参考,具体如下: protected void Page_Load(object sender, EventArgs e) { WebRequest myrequest = WebRequest.Create("http://xxxxx/userface.jpg"); WebResponse myresponse = myrequest.GetResponse(); Stream imgstream = myresponse.
-
C#实现的基于二进制读写文件操作示例
本文实例讲述了C#实现的基于二进制读写文件操作.分享给大家供大家参考,具体如下: using System; using System.IO; class MyStream { private const string FILE_NAME = "Test.data"; public static void Main(String[] args) { // Create the new, empty data file. if (File.Exists(FILE_NAME)) { Con
-
C#读取二进制文件方法分析
本文较为详细的分析了C#读取二进制文件方法.分享给大家供大家参考.具体分析如下: 当想到所有文件都转换为 XML时,确实是一件好事.但是,这并非事实.仍旧还有大量的文件格式不是XML,甚至也不是ASCII.二进制文件仍然在网络中传播,储存在磁盘上,在应用程序之间传递.相比之下,在处理这些问题方面,它们比文本文件显得更有效率些. 在 C 和 C++ 中,读取二进制文件还是很容易的.除了一些开始符(carriage return)和结束符(line feed)的问题,每一个读到C/C++中的文件都是
-
C#下载文件(TransmitFile/WriteFile/流方式)实例介绍
复制代码 代码如下: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; usi
-
C#通过流写入一行数据到文件的方法
本文实例讲述了C#通过流写入一行数据到文件的方法.分享给大家供大家参考.具体如下: using System; using System.IO; public class WriteFileStuff { public static void Main() { FileStream fs = new FileStream("c:\\tmp\\WriteFileStuff.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWrit
-
C# 向二进制文件进行读写的操作方法
完整代码如下: 引入命名空间: 复制代码 代码如下: using System.IO; 完整代码: 复制代码 代码如下: namespace BinaryStreamApp { class Program { static void Main(string[] args) { //为文件打开一个二进制写入器 FileStream fs; fs = new Fil
随机推荐
- Python使用正则表达式实现文本替换的方法
- Ruby连接使用windows下sql server数据库代码实例
- Js+Flash实现访问剪切板操作
- 使用C语言扩展Python程序的简单入门指引
- JS字符串的切分用法实例
- 使用JS实现图片展示瀑布流效果的实例代码
- js 增强型title信息提示效果
- JDBCTM 指南:入门3 - DriverManager
- Bootstrap面板学习使用
- JS+CSS实现简单的二级下拉导航菜单效果
- Windows SVN服务器搭建方法
- 详解Nginx中的重定向功能
- 基于静态Singleton模式的使用介绍
- Android TimeLine 时间节点轴的实现实例代码
- DHCP服务
- PHP实现生成模糊图片的方法示例
- python 设置文件编码格式的实现方法
- vue发送websocket请求和http post请求的实例代码
- PHP实现的AES 128位加密算法示例
- Android仿qq顶部消息栏效果
