Creating a text file

Description



We can create a text file programmatically
The simple snippet shows how to create text file.

Imports System.IO

Module Module5
Sub main()
//creating file info object and naming a file
Dim f As FileInfo = New FileInfo("c:\test.txt")
//creating file stream object for file
Dim fs As FileStream = f.Create()
//listing creation time,attributes,fullname
Console.WriteLine("creation time:{0}", f.CreationTime)
Console.WriteLine("attributes :{0}", f.Attributes.ToString())
Console.WriteLine("full name:{0}", f.FullName)
End Sub
End Module


Explanation:
The file is created using create() .


Comments

Author: Prakash kumar pothal18 Feb 2010 Member Level: Gold   Points : 2

How to crate a text file .just see the below code

DirectoryInfo dir = new DirectoryInfo();

if (dir.Exists == false)
dir.Create();

if (File.Exists(string path))
{
StreamWriter SW;
SW = File.AppendText();
SW.Write();
SW.Close();
}
else
{
FileStream FileUp = new FileStream(string path, FileMode, FileAccess);
StreamWriter SW = new StreamWriter(FileUp);
SW.Write();
SW.Close();
}

and also keep in data in the text files.


Regards,
prakash



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: