CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

急!!!在线等待回答

楼主Jem(Jem)2003-09-03 13:35:17 在 .NET技术 / C# 提问

c#或vb.net中,如何二进制写文件?有实例代码更好. 问题点数:100、回复次数:8Top

1 楼angxain(卖女孩的小火财)回复于 2003-09-03 13:42:20 得分 0

這個不知道對你有沒能用哦  
   
                                                                      DataRow   dr   =   t.Rows.Find(new   object[]{intLSH});  
  byte[]   mydata   =   ((byte[])dr["TZ"]);  
  FileStream   newFile   =   null;  
  newFile   =   new   FileStream("aaa.dwg",FileMode.Create);  
  newFile.Write(mydata,0,mydata.Length);  
  newFile.Close();Top

2 楼cnhgj(戏子) (没时间练太极)回复于 2003-09-03 13:45:22 得分 0

Structure   CustomerRecord    
        Public   OrderNumber   As   Integer  
        Public   Name   As   String  
        Public   OrderDate   As   Date  
  End   Structure  
   
  Sub   WriteData()  
        Dim   MyRecord   As   CustomerRecord  
        Dim   RecordNumber   As   Integer  
        Dim   RecordDate   As   Date  
        '   打开文件进行随机访问。  
        FileOpen(1,   "C:\TESTFILE.txt",   OpenMode.Binary)  
        For   RecordNumber   =   1   To   3       '   循环   3   次。  
              MyRecord.OrderNumber   =   RecordNumber         '   定义   OrderNumber。  
              MyRecord.OrderDate   =   RecordDate                     '   定义   OrderDate。  
              MyRecord.Name   =   "我的姓名"   &   RecordNumber   '   创建字符串。  
              FilePut(1,   MyRecord)                                   '   将记录写入文件。  
        Next   RecordNumber  
        FileClose(1)  
  End   Sub  
  Top

3 楼Jem(Jem)回复于 2003-09-03 13:51:31 得分 0

换句话说吧,我现在已经有一个字串"145     tghd   为什么",如果想将该字串写进文件中,该怎么处理?(注:该字串中有全角文字)Top

4 楼jjcccc(就这样吧)回复于 2003-09-03 13:52:15 得分 0

FileStream   fs=new   FileStream(@"test.log",FileMode.Create,FileAccess.Write);  
   
  //写入字节  
  byte   theByte=100;  
  fs.WriteByte(theByte);  
   
  //写入字节数组  
  byte[]   theBytes;//实际写入时需要初始化该数组  
  int   nBytes;             //实际写入时需要初始化,写入的字节数  
  fs.Write(theBytes,0,nBytes);Top

5 楼jjcccc(就这样吧)回复于 2003-09-03 13:59:53 得分 0

string   s="145     tghd   为什么";  
   
  byte[]   theBytes=SysTem.Text.Encoding.GetBytes(s);  
   
  然后再将之写入文件。Top

6 楼win911(Vincent)回复于 2003-09-03 14:34:43 得分 100

private   const   string   FILE_NAME   =   @"C:\Documents   and   Settings\Administrator\桌面\Win   Odds.htm";  
  private   const   string   file_name   =   @"C:\Documents   and   Settings\Administrator\桌面\Win.txt";  
  private   void   button1_Click(object   sender,   System.EventArgs   e)  
  {  
  if   (!File.Exists(FILE_NAME))    
  {  
  Console.WriteLine("{0}   does   not   exist.",   FILE_NAME);  
  return;  
  }  
   
  //以繁体字的encoding形式读取文件  
  StreamReader   sr   =   new   StreamReader(FILE_NAME,System.Text.Encoding.GetEncoding(950)   ,true,200);  
   
  //以简体字的encoding写入文件  
  // StreamWriter   sw=   new   StreamWriter(file_name,false,System.Text.Encoding.GetEncoding(936),200);  
  String   input;  
  input=sr.ReadToEnd();  
  RG(input,sr);  
   
  Console.WriteLine   ("The   end   of   the   stream   has   been   reached.");  
  sr.Close();  
  }  
  private   void   RG(string   inputString,System.IO.StreamReader     ss)  
  {  
    System.Text.RegularExpressions.Regex   r;  
  System.Text.RegularExpressions.Match   m;  
   
  StreamWriter   sw=   new   StreamWriter(file_name,false,System.Text.Encoding.GetEncoding(936),200);  
  String   input;  
  input=ss.ReadLine   ();  
                           
     
  r   =   new   System.Text.RegularExpressions.Regex(">(\\S)([^陣容往績心水推介賠率走勢圖][^(\\<*\\>)]*)<\\S",System.Text.RegularExpressions.RegexOptions.IgnoreCase|System.Text.RegularExpressions.RegexOptions.Compiled     );  
  for   (m   =   r.Match(inputString);   m.Success;   m   =   m.NextMatch())    
  {  
  sw.WriteLine(m.ToString());  
   
  }  
  sw.Close();  
  }  
  以前的一部分代码,没整理,乱了点。  
  读写文件什么的都在里面了。Top

7 楼Jem(Jem)回复于 2003-09-03 14:34:47 得分 0

谢了,各位Top

8 楼Jem(Jem)回复于 2003-09-03 14:45:20 得分 0

大侠win911(Young),强~~~~~~~~~~~~~~~~~~~~Top

相关问题

  • 很急,在线等待回答,谢谢!!!
  • 回答就给分!!很急!在线等待!问题不大!
  • 急 !谁回答正确50分! 在线等待
  • VB简单问题,请回答,高分相赠,在线等待!!!急急急!!!
  • 在线等待回答!多谢了!请看这个问题!很急的 !
  • 急!能不能不用FILEBOX提交文件??在线等待!回答有分!!
  • 菜鸟问题(在线等待回答)
  • 在线等待!先回答者得分!
  • 菜鸟问题,分不多,但只要回答立刻给分,在线等待。急急急急急急急急!
  • 简单问题 在线等待回答 简单问题 在线等待回答 简单问题 在线等待回答 简单问题 在线等待回答 简单问题 在线等待回答

关键词

  • 文件
  • myrecord
  • 写入
  • recordnumber
  • thebytes
  • newfile
  • ordernumber
  • streamwriter
  • filestream
  • mydata

得分解答快速导航

  • 帖主:Jem
  • win911

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo