how to write to a file when there is no exceptions.
-
Hi All, i am using C#.net.And i am reading a file and then writing it to another file. The code is as follows:
StreamReader reader = new StreamReader("Some Path"); StreamWriter writer = new StreamWriter( "Some Path", false ); string line; while ( (line = reader.ReadLine()) != null ) { if(some condition) { throw new ApplicationException("Unrecognised File Format"); } ..... .....some more "if" conditions.. writer.WriteLine( "\n {0} = {1},", sometext, somevalue); } writer.Close(); reader.Close();
So now if we observe,when any exception occurs, the application prints "Unrecognised File Format" and it doesn't write anything to the file.Also the output file is created first. Now what i require is: Output File should be created only when there are no exceptions in the reading of the file."Some text" and "some values" are set when using the while loop..So how can i create a file when there are no exceptions in reading. Plz Help Me!! Thanx in ADVANCE.. -
Hi All, i am using C#.net.And i am reading a file and then writing it to another file. The code is as follows:
StreamReader reader = new StreamReader("Some Path"); StreamWriter writer = new StreamWriter( "Some Path", false ); string line; while ( (line = reader.ReadLine()) != null ) { if(some condition) { throw new ApplicationException("Unrecognised File Format"); } ..... .....some more "if" conditions.. writer.WriteLine( "\n {0} = {1},", sometext, somevalue); } writer.Close(); reader.Close();
So now if we observe,when any exception occurs, the application prints "Unrecognised File Format" and it doesn't write anything to the file.Also the output file is created first. Now what i require is: Output File should be created only when there are no exceptions in the reading of the file."Some text" and "some values" are set when using the while loop..So how can i create a file when there are no exceptions in reading. Plz Help Me!! Thanx in ADVANCE..