zoukankan      html  css  js  c++  java
  • StreamReader实例

    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;
    using System.Collections;
    using System.IO;

    /// <summary>
    /// file 的摘要说明
    /// </summary>

    public class file
    {
        
    public file()
        
    {
            
    //
            
    // TODO: 在此处添加构造函数逻辑
            
    //
        }

        
    static void Main()
        
    {
            StreamReader objreader 
    = new StreamReader("F:\\upfile\\t.txt");
            
    string sline="";
            ArrayList arrtext 
    = new ArrayList();
            
    while (sline != null)
            
    {
                sline 
    = objreader.ReadLine();
                
    if (sline != null)
                    arrtext.Add(sline);

            }
     objreader.Close();
            
    foreach(string ss in arrtext)
                Console.WriteLine(ss);
                Console.ReadLine();

        }

    }

    写文件
    using System;
    using System.IO;

    class Test 
    {
        
        
    public static void Main() 
        
    {
            
    string path = @"c:\temp\MyTest.txt";

            
    try 
            
    {
                
    if (File.Exists(path)) 
                
    {
                    File.Delete(path);
                }


                
    using (StreamWriter sw = new StreamWriter(path)) 
                
    {
                    sw.WriteLine(
    "This");
                    sw.WriteLine(
    "is some text");
                    sw.WriteLine(
    "to test");
                    sw.WriteLine(
    "Reading");
                }


                
    using (StreamReader sr = new StreamReader(path)) 
                
    {
                    
    //This allows you to do one Read operation.
                    Console.WriteLine(sr.ReadToEnd());
                }

            }
     
            
    catch (Exception e) 
            
    {
                Console.WriteLine(
    "The process failed: {0}", e.ToString());
            }

        }

    }

  • 相关阅读:
    正则表达式$的一些用法
    基本类型数据转换(int,char,byte)
    IntelliJ Idea 2017 免费激活方法
    jrebel license server 激活方法
    linux 完全关闭tomcat
    spring data jpa自定义bean字段映射
    idea 启动调试模式总提示端口58346被占用问题
    java使用jsch连接linux
    福大软工 · BETA 版冲刺前准备(团队)
    Alpha 事后诸葛亮
  • 原文地址:https://www.cnblogs.com/binlyzhuo/p/1218803.html
Copyright © 2011-2022 走看看