• Tidak ada hasil yang ditemukan

Streaming Sequential Text File

N/A
N/A
Protected

Academic year: 2025

Membagikan "Streaming Sequential Text File"

Copied!
4
0
0

Teks penuh

(1)

Streaming Sequential Text File

1

(2)

Public Class Form1

Dim FILE_NAME As String = "C:\Users\Ashwaq\Documents\Visual Studio 2010\

Projects\text.txt"

Private Sub btnopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopen.Click

If System.IO.File.Exists(FILE_NAME) = True Then

Dim objReader As New System.IO.StreamReader(FILE_NAME) TextBox1.Text = objReader.ReadToEnd

objReader.Close() Else

MessageBox.Show("File Does Not Exist") End If

End Sub

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click

Dim TextLine As String = ""

If System.IO.File.Exists(FILE_NAME) = True Then

Dim objReader As New System.IO.StreamReader(FILE_NAME) Do While objReader.Peek() <> -1

TextLine = TextLine & objReader.ReadLine() & " "

TextBox1.Text = TextLine Loop

Else

MessageBox.Show("File Does Not Exist") End If

End Sub

Private Sub BTNSAVE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNSAVE.Click

If System.IO.File.Exists(FILE_NAME) = True Then

Dim objWriter As New System.IO.StreamWriter(FILE_NAME) objWriter.Write(TextBox1.Text)

objWriter.Close()

MessageBox.Show("Text written to file") Else

MessageBox.Show("File Does Not Exist") End If

2

(3)

End Sub

Private Sub btnwrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnwrite.Click

Dim i As Integer

Dim aryText(4) As String aryText(0) = "Mary WriteLine"

aryText(1) = "Had"

aryText(2) = "A"

aryText(3) = "Little"

aryText(4) = "One"

Dim objWriter As New System.IO.StreamWriter(FILE_NAME) For i = 0 To 4

objWriter.WriteLine(aryText(i)) Next

objWriter.Close() End Sub

Private Sub btnAppend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAppend.Click

Dim i As Integer

Dim aryText(4) As String

aryText(0) = "Mary ,Append Text"

aryText(1) = "Had"

aryText(2) = "Another"

aryText(3) = "Little"

aryText(4) = "One"

Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True) For i = 0 To 4

objWriter.WriteLine(aryText(i)) Next

objWriter.Close()

MessageBox.Show("Text Appended to the File") End Sub

Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click

Dim FileToCopy As String Dim NewCopy As String

FileToCopy = "C:\Users\Ashwaq\Documents\Visual Studio 2010\Projects\

text.txt"

NewCopy = "C:\Users\Ashwaq\Documents\Visual Studio 2010\Projects\

SecondNewText.txt"

3

(4)

If System.IO.File.Exists(FileToCopy) = True And System.IO.File.Exists(NewCopy) = False Then

System.IO.File.Copy(FileToCopy, NewCopy) MessageBox.Show("File Copied")

Else

MessageBox.Show("File already Exists") End If

End Sub

Private Sub btnMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMove.Click

Dim FileToMove As String Dim MoveLocation As String

FileToMove = "C:\Users\Ashwaq\Documents\Visual Studio 2010\Projects\

NewText.txt"

MoveLocation = "C:\Users\Ashwaq\Documents\NewText.txt"

If System.IO.File.Exists(FileToMove) = True And System.IO.File.Exists(MoveLocation) = False Then

System.IO.File.Move(FileToMove, MoveLocation) MessageBox.Show("File Moved")

Else

MessageBox.Show("File already Exists") End If

End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

Dim FileToDelete As String

FileToDelete = "C:\Users\Ashwaq\Documents\Visual Studio 2010\Projects\

SecondNewText.txt"

If System.IO.File.Exists(FileToDelete) = True Then System.IO.File.Delete(FileToDelete)

MessageBox.Show("File Deleted") Else

MessageBox.Show("File Does Not Exist") End If

End Sub End Class

4

Referensi

Dokumen terkait

Private Sub BtnBilangan_Click(ByVal sender As System.. EventArgs ) Handles btnSaveAudio.Click.. dlgSaveAudio.ShowDialog()

Chunk exchange between the users are considered as the sender-receiver game model to Research Problem Definition Objectives Questions Review Previous Findings Sybil detection

For example: C:\Users\Sierra Rowan\Documents\Projects\suppliers This file path means that the file is in the suppliers folder, which is in the Projects folder, which is in the