stream was not readable._.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > stream was not readable.

stream was not readable.

 2013/8/22 19:11:27  沧海一滴  博客园  我要评论(0)
  • 摘要:StreamWriter使用时的报错情况:streamwasnotreadable.错误原因:没有指定StreamWriter的写入文件正确代码示例1:byte[]businessDataByte=dh.downFile(dataActionUrl);logger.InfoFormat("{0}",businessDataByte.Length);StreamWritersw=newStreamWriter("a.txt"));sw.Write
  • 标签:not

StreamWriter使用时的报错情况:

stream was not readable.

错误原因:

没有指定StreamWriter的写入文件

正确代码示例1:

class="csharpcode">byte[] businessDataByte = dh.downFile(dataActionUrl);
logger.InfoFormat("{0}", businessDataByte.Length);

StreamWriter sw = new StreamWriter("a.txt"));
sw.Write(Encoding.UTF8.GetString(businessDataByte));
sw.Flush();
sw.Close();

示例2:

using System;
using System.IO;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string fileName = "test.txt";
            string textToAdd = "Example text in file";

            using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
            {
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    writer.Write(textToAdd);
                }
            }            
        }
    }
}
上一篇: Ubuntu Edge背后的手机和PC融合之路 下一篇: 没有下一篇了!
发表评论
用户名: 匿名