這篇文章將為大家詳細(xì)講解有關(guān)如何淺析.NET寫入文本文件的操作,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的橋西網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
.NET寫入文本文件的操作時(shí)需要注意注意
Visual Basic 用戶可以選擇使用由 My.Computer.FileSystem 對象提供的方法和屬性進(jìn)行文件 I/O。
.NET寫入文本文件的操作示例Visual Basic實(shí)現(xiàn)添加文本
Imports System Imports System.IO Class Test Public Shared Sub Main() ' Create an instance of StreamWriter to write text to a file. Using sw As StreamWriter = New StreamWriter("TestFile.txt") ' Add some text to the file. sw.Write("This is the ") sw.WriteLine("header for the file.") sw.WriteLine("-------------------") ' Arbitrary objects can also be written to the file. sw.Write("The date is: ") sw.WriteLine(DateTime.Now) sw.Close() End Using End Sub End Class
.NET寫入文本文件的操作示例C#實(shí)現(xiàn)添加文本
using System; using System.IO; class Test { public static void Main() { // Create an instance of StreamWriter to write text to a file. // The using statement also closes the StreamWriter. using (StreamWriter sw = new StreamWriter("TestFile.txt")) { // Add some text to the file. sw.Write("This is the "); sw.WriteLine("header for the file."); sw.WriteLine("-------------------"); // Arbitrary objects can also be written to the file. sw.Write("The date is: "); sw.WriteLine(DateTime.Now); } } }
.NET寫入文本文件的操作示例Visual Basic實(shí)現(xiàn)寫入一個(gè)字符串
Option Explicit On Option Strict On Imports System Imports System.IO Public Class TextToFile Private Const FILE_NAME As String = "MyFile.txt" Public Shared Sub Main() If File.Exists(FILE_NAME) Then Console.WriteLine("{0} already exists.", FILE_NAME) Return End If Using sw As StreamWriter = File.CreateText(FILE_NAME) sw.WriteLine("This is my file.") sw.WriteLine("I can write ints {0} or floats {1}, and so on.", 1, 4.2) sw.Close() End Using End Sub End Class
.NET寫入文本文件的操作示例C#實(shí)現(xiàn)寫入一個(gè)字符串
using System; using System.IO; public class TextToFile { private const string FILE_NAME = "MyFile.txt"; public static void Main(String[] args) { if (File.Exists(FILE_NAME)) { Console.WriteLine("{0} already exists.", FILE_NAME); return; } using (StreamWriter sw = File.CreateText(FILE_NAME)) { sw.WriteLine ("This is my file."); sw.WriteLine ("I can write ints {0} or floats {1}, and so on.", 1, 4.2); sw.Close(); } } }
關(guān)于如何淺析.NET寫入文本文件的操作就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。