try{Console.WriteLine("———————————————————————————————————————————");Console.WriteLine("Program to perform the operations on a file");Console.WriteLine("———————————————————————————————————————————");FileStreamf=newFileStream("/home/kodingwindow/Trial.txt",FileMode.Append);//"Hi There!" text is present in Trial.txtStreamWriterw=newStreamWriter(f);w.WriteLine("Welcome to KodingWindow!");w.Close();f.Close();FileStreamfs=newFileStream("/home/kodingwindow/Trial.txt",FileMode.Open);StreamReaderr=newStreamReader(fs);stringline="";while((line=r.ReadLine())!=null){Console.WriteLine(line);}r.Close();fs.Close();Console.WriteLine("———————————————————————————————————————————");}catch(FileNotFoundException){Console.WriteLine("File not found");}catch(Exceptione){Console.WriteLine(e);}finally{Thread.Sleep(5000);}
Output
kodingwindow@kw:~/csharp$ dotnet run
———————————————————————————————————————————
Program to perform the operations on a file
———————————————————————————————————————————
Hi There!
Welcome to KodingWindow!
———————————————————————————————————————————
kodingwindow@kw:~/csharp$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.