using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
[Link]("Please enter a name for the new directory:");
string DirName = [Link]();
// Checking if string is empty or not
if (DirName != [Link])
{
// Creating the Directory
[Link]("D:\\"+DirName);
// Checking Directory is created
// Successfully or not
if ([Link](DirName))
{
[Link]("The directory was created!");
[Link]();
}
}
}
}
}
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
[Link]("Enter the directory name you want to delete:");
string DirName = [Link]();
if ([Link]("D://"+DirName))
{
[Link]("D://"+DirName);
if([Link]("D://"+DirName) == false)
{
[Link]("Directory deleted successfully...");
}
}
else
{
[Link]("Directory {0} does not exist!", DirName);
[Link]();
}
}
}
}
C# - Stream
C# includes following standard IO (Input/Output) classes to read/write from different sources like files,
memory, network, isolated storage, etc.
Stream: [Link] is an abstract class that provides standard methods to transfer bytes (read, write,
etc.) to the source. It is like a wrapper class to transfer bytes. Classes that need to read/write bytes from a
particular source must implement the Stream class.
StreamReader: StreamReader is a helper class for reading characters from a Stream by converting bytes into
characters using an encoded value. It can be used to read strings (characters) from different Streams like
FileStream, MemoryStream, etc.
StreamWriter: StreamWriter is a helper class for writing a string to a Stream by converting characters into
bytes. It can be used to write strings to different Streams such as FileStream, MemoryStream, etc.
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Create object of FileInfo for specified path
FileInfo fi = new FileInfo(@"D:\skcollege\[Link]");
//Open file for Read\Write
FileStream fs = [Link]([Link],[Link], [Link]);
//Create StreamWriter object to write string to FileSream
StreamWriter sw = new StreamWriter(fs);
[Link]("line 1 from streamwriter");
[Link]("line 2 line from streamwriter");
[Link]();
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
FileInfo fi = new FileInfo(@"D:\skcollege\[Link]");
FileStream fs = [Link]([Link], [Link], [Link]);
StreamReader sr = new StreamReader(fs);
string fileContent = [Link]();
[Link](fileContent);
[Link]();
[Link]();
[Link]();
// Line by Line Reading
1.// Write file contents on console.
2. using (StreamReader sr = [Link](fileName))
3. {
4. string s = "";
5. while ((s = [Link]()) != null)
6. {
7. [Link](s);
8. }
9. }
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
The BinaryReader and BinaryWriter classes are used for reading from and writing to a binary file.
The BinaryReader and BinaryWriter classes are used for reading from and writing to a binary file.