1: /*
2: * Created by SharpDevelop.
3: * User: Eric Yih
4: * Date: 2008-12-14
5: * Time: 16:45
6: *
7: * To change this template use Tools | Options | Coding | Edit Standard Headers.
8: */
9: using System;
10: using System.IO;
11: using System.Collections;
12: using System.Diagnostics;
13:
14: namespace Studying.MyStream
15: {
16: class MyStream
17: {
18: public void ReadFile(string filepath)
19: {
20: try
21: {
22: StreamReader sr = new StreamReader(filepath);
23:
24: string sLine = "";
25: ArrayList arrText = new ArrayList();
26: while(sLine != null)
27: {
28: sLine = sr.ReadLine();
29: if (sLine != null)
30: {
31: arrText.Add(sLine);
32: }
33: }
34: sr.Close();
35:
36: foreach(string output in arrText)
37: {
38: Console.WriteLine(output);
39: }
40: }
41: catch(Exception ex)
42: {
43: throw new Exception(ex.Message);
44: }
45: }
46:
47: public void WriteFile(string username, string password)
48: {
49: try
50: {
51: //Initialize StreamWriter as a Object "sw", and specify the file name and directory.
52: StreamWriter sw = new StreamWriter(System.Environment.CurrentDirectory + "\\userinfo.bat");
53:
54: sw.WriteLine(username);
55: sw.WriteLine(password);
56:
57: //Close Stream
58: sw.Close();
59: }
60: catch(Exception ex)
61: {
62: throw new Exception(ex.Message);
63: }
64: }
65:
66: public static void Main(string[] args)
67: {
68: String FilePath = System.Environment.CurrentDirectory + "\\userinfo.bat";
69:
70: //Check if the file exist on the current directory
71: if(File.Exists(FilePath))
72: {
73: File.Delete(System.Environment.CurrentDirectory + "\\userinfo.bat");
74: }
75:
76: MyStream myStream = new MyStream();
77:
78: myStream.WriteFile("root","password");
79:
80: myStream.ReadFile(FilePath);
81:
82: if(File.Exists(FilePath))
83: {
84: File.Delete(System.Environment.CurrentDirectory + "\\userinfo.bat");
85: }
86: }
87: }
88: }
2: * Created by SharpDevelop.
3: * User: Eric Yih
4: * Date: 2008-12-14
5: * Time: 16:45
6: *
7: * To change this template use Tools | Options | Coding | Edit Standard Headers.
8: */
9: using System;
10: using System.IO;
11: using System.Collections;
12: using System.Diagnostics;
13:
14: namespace Studying.MyStream
15: {
16: class MyStream
17: {
18: public void ReadFile(string filepath)
19: {
20: try
21: {
22: StreamReader sr = new StreamReader(filepath);
23:
24: string sLine = "";
25: ArrayList arrText = new ArrayList();
26: while(sLine != null)
27: {
28: sLine = sr.ReadLine();
29: if (sLine != null)
30: {
31: arrText.Add(sLine);
32: }
33: }
34: sr.Close();
35:
36: foreach(string output in arrText)
37: {
38: Console.WriteLine(output);
39: }
40: }
41: catch(Exception ex)
42: {
43: throw new Exception(ex.Message);
44: }
45: }
46:
47: public void WriteFile(string username, string password)
48: {
49: try
50: {
51: //Initialize StreamWriter as a Object "sw", and specify the file name and directory.
52: StreamWriter sw = new StreamWriter(System.Environment.CurrentDirectory + "\\userinfo.bat");
53:
54: sw.WriteLine(username);
55: sw.WriteLine(password);
56:
57: //Close Stream
58: sw.Close();
59: }
60: catch(Exception ex)
61: {
62: throw new Exception(ex.Message);
63: }
64: }
65:
66: public static void Main(string[] args)
67: {
68: String FilePath = System.Environment.CurrentDirectory + "\\userinfo.bat";
69:
70: //Check if the file exist on the current directory
71: if(File.Exists(FilePath))
72: {
73: File.Delete(System.Environment.CurrentDirectory + "\\userinfo.bat");
74: }
75:
76: MyStream myStream = new MyStream();
77:
78: myStream.WriteFile("root","password");
79:
80: myStream.ReadFile(FilePath);
81:
82: if(File.Exists(FilePath))
83: {
84: File.Delete(System.Environment.CurrentDirectory + "\\userinfo.bat");
85: }
86: }
87: }
88: }
浙公网安备 33010602011771号