{"id":152,"date":"2009-07-24T12:50:17","date_gmt":"2009-07-24T11:50:17","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=152"},"modified":"2009-07-24T12:56:19","modified_gmt":"2009-07-24T11:56:19","slug":"read-and-write-to-files","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/read-and-write-to-files\/","title":{"rendered":"Read and Write to files"},"content":{"rendered":"<p><span id=\"zipfile\"><a href='http:\/\/www.codingfriends.com\/wp-content\/uploads\/2009\/07\/readwrite.zip'><\/a><\/span>This tutorial is about how to read and write from\/to a file (textual file). <\/p>\n<p>First of all define the files that are for the input and output filenames.<\/p>\n<p>NOTE: the { } are the begin and end of a code structure, e.g. While begin; do something; end;<\/p>\n<pre lang=\"csharp\">\r\nstring fileName = \"country.txt\";\r\nstring outFileName = \"sqlcountry.txt\";\r\n\r\n\/\/make sure that the file is present\r\nif (File.Exists(fileName))\r\n{\r\n\r\n\/\/Setup the output file object, using a StreamWriter to write to files.\r\n       using (StreamWriter SWriter = new StreamWriter(outFileName))\r\n       {\r\n\r\n\/\/Setup the input file object, \r\n       using (StreamReader SReader = new StreamReader(fileName))\r\n       {\r\n\r\n\/\/The line is the input line from the input file.\r\n       String line;\r\n\r\n\/\/While assigning the line from the input file is valid\r\n       while ((line = SReader.ReadLine()) != null){\r\n\r\n\/\/Write to the output file some different text.\r\n       SWriter.WriteLine(\"insert into country(place) values(\\\"\" + line + \"\\\");\");\r\n}\r\n<\/pre>\n<p>I have attached all of the required files to be able to test this tutorial.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial is about how to read and write from\/to a file (textual file). First of all define the files that are for the input and output filenames. NOTE: the { } are the begin and end of a code structure, e.g. While begin; do something; end; string fileName = &#8220;country.txt&#8221;; string outFileName = &#8220;sqlcountry.txt&#8221;; &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/read-and-write-to-files\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Read and Write to files<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[14,398,13,400],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-c_sharp","tag-c-sharp","tag-linux","tag-mono","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":4,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}