StreamReader 和 StreamWriter 简单调用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*              #########                      
              ############                    
              #############                   
             ##  ###########                  
            ###  ###### #####                 
            ### #######   ####                
           ###  ########## ####               
          ####  ########### ####              
         ####   ###########  #####            
        #####   ### ########   #####          
       #####   ###   ########   ######        
      ######   ###  ###########   ######      
     ######   #### ##############  ######     
    #######  #####################  ######    
    #######  ######################  ######   
   #######  ###### #################  ######  
   #######  ###### ###### #########   ######  
   #######    ##  ######   ######     ######  
   #######        ######    #####     #####   
    ######        #####     #####     ####    
     #####        ####      #####     ###     
      #####       ###        ###      #       
        ###       ###        ###             
         ##       ###        ###              
__________#_______####_______####______________
    身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
                我们的未来没有BUG             
* ==============================================================================
* Filename: Text07
* Created:  $time$
* Author:   WYC
* Purpose:  StreamReader 和 StreamWriter 简单调用
* ==============================================================================
*/
using System.Text;
using System.IO;
using UnityEngine;
 
public class Text07 : MonoBehaviour {
 
 
    void Start() {
        //StreamReader();
        //StreamWriter();
        //StreamWriterApp();
    }
    /// <summary>
    /// 读取一个文本文件
    /// </summary>
    public void StreamReader(){
        using (StreamReader sr = new StreamReader(@"C:\Users\Administrator.PC-201709211725\Desktop\王.txt", Encoding.Default))
        {
            while (!sr.EndOfStream)
            {
                //只读取第一行
                print(sr.ReadLine());
            }
        }
    }
    /// <summary>
    /// 写入一个文本文件 (覆盖)
    /// </summary>
    public void StreamWriter()
    {
        using (StreamWriter sw = new StreamWriter(@"C:\Users\Administrator.PC-201709211725\Desktop\王.txt"))
        {
            sw.Write("我真帅");
            print("写入OK");
        }
    }
    /// <summary>
    /// 写入一个文本文件 (未覆盖)
    /// </summary>
    public void StreamWriterApp()
    {
        using (StreamWriter sw = new StreamWriter(@"C:\Users\Administrator.PC-201709211725\Desktop\王.txt",true))
        {
            sw.Write("你真帅");
            print("写入OK");
        }
    }
}

  

posted @   一只默默奮鬥的程序菌  阅读(187)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示