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());
            }

        }

    }

  • 相关阅读:
    学习java之路2
    学习java之路1
    【JavaSE】如何安装jdk以及java的环境配置(超详细) eclipse的安装和简单使用
    微课堂的使用体验
    Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
    docker概念
    Leetcode103_Binary-tree-zigzag-level-order-traversal
    二叉树广度优先遍历和深度优先遍历
    centos7 安装docker
    yum update 出错
  • 原文地址:https://www.cnblogs.com/binlyzhuo/p/1218803.html
Copyright © 2011-2022 走看看