CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  VB.NET

文件操作

楼主houfuzhu(**追^_^梦**)2006-06-02 13:45:54 在 .NET技术 / VB.NET 提问

1.如何在项目文件的同一目录下建立一个文本件  
  2.如何把字符串写到文本文件去  
  3.如何读取文本文件里的字符串 问题点数:20、回复次数:4Top

1 楼hdt(倦怠)回复于 2006-06-02 13:48:55 得分 3

ms-help://MS.MSDNQTR.2003FEB.2052/cpguide/html/cpconwritingtexttofile.htmTop

2 楼copico(北北)回复于 2006-06-02 13:51:21 得分 6

dim   ft   as   new   io.filestream("123.txt",openorcreate)  
  dim   dw   as   new   io.streamwrite(ft)  
   
  dw.writeline("这是第一行")  
  dw.writeline("这是第二行")  
   
  dw.close()  
  ft.close()  
  ////////////////////  
  读  
  dim   ft   as   new   io.filestream("123.txt",openorcreate)  
  dim   dr   as   new   io.streamread(ft)  
   
  msgbox   dr.readline()   '读第一行  
  msgbox   dr.readline()   '读第二行  
  dr.close()  
  ft.close()Top

3 楼why2002plus()回复于 2006-06-02 13:56:45 得分 7

1、System.IO.File.Create(Application.StartupPath   +   "e.txt")  
  2、写文件              
        Dim   sw   As   StreamWriter   =   New   StreamWriter(Application.StartupPath   +   "e.txt")  
                    sw.Write("This   is   the   ")  
                  sw.WriteLine("header   for   the   file.")  
                  sw.WriteLine("-------------------")  
                  sw.Write("The   date   is:   ")  
                  sw.WriteLine(DateTime.Now)  
                  sw.Close()  
  3、读文件  
      Dim   sr   As   StreamReader   =   New   StreamReader(Application.StartupPath   +   "e.txt")  
                          Dim   line   As   String  
                          Do  
                                  line   =   sr.ReadLine()  
                                  Console.WriteLine(Line)  
                          Loop   Until   line   Is   Nothing  
                          sr.Close()  
                  Catch   E   As   Exception  
                          '   Let   the   user   know   what   went   wrong.  
                          Console.WriteLine("The   file   could   not   be   read:")  
                          Console.WriteLine(E.Message)  
                  End   Try  
   
  Top

4 楼bitpolar(独自看天)回复于 2006-06-02 14:29:51 得分 4

在MSDN里面输入个File   或者   FileInfo   就能解决Top

相关问题

关键词

得分解答快速导航

  • 帖主:houfuzhu
  • hdt
  • copico
  • why2002plus
  • bitpolar

相关链接

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

广告也精彩

反馈

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