कंप्यूटर प्रोग्रामिंग/फ़ाइलें/विजुअल बेसिक .नेट

' This program creates a file, adds data to the file, displays the file,
' appends more data to the file, displays the file, and then deletes the file.
' It will not run if the file already exists.

Public Module Files
 
    Sub Main()
        Const FILENAME As String = "~file.txt"

        If(System.IO.File.Exists(FILENAME)) Then
            System.Console.WriteLine("File already exists.\n")
        Else
            CreateFile(FILENAME)
            ReadFile(FILENAME) 
            AppendFile(FILENAME)
            ReadFile(FILENAME)
            DeleteFile(FILENAME)
        End If
    End Sub

    Sub CreateFile(Filename As String)
        Dim File As System.IO.StreamWriter
        Dim C As Single
        Dim F As Single
        
        File = System.IO.File.CreateText(Filename)
        File.WriteLine("C   F")
        For C = 0 To 50
            F = C * 9 / 5 + 32
            File.WriteLine(C.ToString() + "   " + F.ToString())
        Next
        File.Close()
    End Sub
    
    Sub ReadFile(Filename As String)
        Dim File As System.IO.StreamReader
        Dim Line As String
        
        File = System.IO.File.OpenText(Filename)
        Do While True 
            Line = File.ReadLine()
            If Line = Nothing Then
                Exit Do
            End If
            Console.WriteLine(Line)
        Loop
        File.Close()
        Console.WriteLine("")
    End Sub
    
    Sub AppendFile(Filename As String)
        Dim File As System.IO.StreamWriter
        Dim C As Single
        Dim F As Single
        
        File = System.IO.File.AppendText(Filename)
        For C = 51 To 100
            F = C * 9 / 5 + 32
            File.WriteLine(C.ToString() + "   " + F.ToString())
        Next
        File.Close()
    End Sub
    
    Sub DeleteFile(Filename As String)
        System.IO.File.Delete(Filename)
    End Sub
End Module

कोशिश करो

सम्पादन

निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।

यह भी देखें

सम्पादन