日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
.NET寫入文本文件的操作淺析

.NET寫入文本文件的操作是如何實(shí)現(xiàn)的呢?下面我們通過使用VB和C#兩種代碼示例向你演示如何實(shí)現(xiàn)寫入文本文件的操作細(xì)節(jié),希望對(duì)你了解寫入文本文件有所幫助

創(chuàng)新互聯(lián)建站科技有限公司專業(yè)互聯(lián)網(wǎng)基礎(chǔ)服務(wù)商,為您提供四川主機(jī)托管,高防主機(jī),成都IDC機(jī)房托管,成都主機(jī)托管等互聯(lián)網(wǎng)服務(wù)。

***個(gè)示例演示如何向現(xiàn)有文件中添加文本。第二個(gè)示例演示如何創(chuàng)建一個(gè)新文本文件并向其中寫入一個(gè)字符串。 WriteAllText 方法可提供類似的功能。

.NET寫入文本文件的操作時(shí)需要注意注意
 
Visual Basic 用戶可以選擇使用由 My.Computer.FileSystem 對(duì)象提供的方法和屬性進(jìn)行文件 I/O。有關(guān)更多信息,請(qǐng)參見 My.Computer.FileSystem 對(duì)象。

.NET寫入文本文件的操作示例Visual Basic實(shí)現(xiàn)添加文本

 
 
 
  1. Imports System
  2. Imports System.IO
  3. Class Test
  4. Public Shared Sub Main()
  5. ' Create an instance of StreamWriter to write text to a file.
  6. Using sw As StreamWriter = New StreamWriter("TestFile.txt")
  7. ' Add some text to the file.
  8. sw.Write("This is the ")
  9. sw.WriteLine("header for the file.")
  10. sw.WriteLine("-------------------")
  11. ' Arbitrary objects can also be written to the file.
  12. sw.Write("The date is: ")
  13. sw.WriteLine(DateTime.Now)
  14. sw.Close()
  15. End Using
  16. End Sub
  17. End Class

.NET寫入文本文件的操作示例C#實(shí)現(xiàn)添加文本

 
 
 
  1. using System;
  2. using System.IO;
  3. class Test 
  4. {
  5. public static void Main() 
  6. {
  7. // Create an instance of StreamWriter to write text to a file.
  8. // The using statement also closes the StreamWriter.
  9. using (StreamWriter sw = new StreamWriter("TestFile.txt")) 
  10. {
  11. // Add some text to the file.
  12. sw.Write("This is the ");
  13. sw.WriteLine("header for the file.");
  14. sw.WriteLine("-------------------");
  15. // Arbitrary objects can also be written to the file.
  16. sw.Write("The date is: ");
  17. sw.WriteLine(DateTime.Now);
  18. }
  19. }
  20. }

.NET寫入文本文件的操作示例Visual Basic實(shí)現(xiàn)寫入一個(gè)字符串

 
 
 
  1. Option Explicit On 
  2. Option Strict On
  3. Imports System
  4. Imports System.IO
  5. Public Class TextToFile
  6. Private Const FILE_NAME As String = "MyFile.txt"
  7. Public Shared Sub Main()
  8. If File.Exists(FILE_NAME) Then
  9. Console.WriteLine("{0} already exists.", FILE_NAME)
  10. Return
  11. End If
  12. Using sw As StreamWriter = File.CreateText(FILE_NAME)
  13. sw.WriteLine("This is my file.")
  14. sw.WriteLine("I can write ints {0} or floats {1}, and so on.", 1, 4.2)
  15. sw.Close()
  16. End Using
  17. End Sub
  18. End Class

.NET寫入文本文件的操作示例C#實(shí)現(xiàn)寫入一個(gè)字符串

 
 
 
  1. using System;
  2. using System.IO;
  3. public class TextToFile 
  4. {
  5. private const string FILE_NAME = "MyFile.txt";
  6. public static void Main(String[] args) 
  7. {
  8. if (File.Exists(FILE_NAME)) 
  9. {
  10. Console.WriteLine("{0} already exists.", FILE_NAME);
  11. return;
  12. }
  13. using (StreamWriter sw = File.CreateText(FILE_NAME))
  14. {
  15. sw.WriteLine ("This is my file.");
  16. sw.WriteLine ("I can write ints {0} or floats {1}, and so on.", 
  17. 1, 4.2);
  18. sw.Close();
  19. }
  20. }
  21. }

.NET寫入文本文件的操作示例的基本實(shí)現(xiàn)就向你介紹到這里,希望對(duì)你了解.NET寫入文本文件的操作有所幫助。


網(wǎng)頁題目:.NET寫入文本文件的操作淺析
當(dāng)前路徑:http://www.dlmjj.cn/article/dpdgiod.html