private void readFile() { StreamReader reader = null; try { reader = new StreamReader(File.OpenRead(inputPayslipsFilePath)); } catch (DirectoryNotFoundException dnfe) { // it's ok, we don't have payslips yet. Console.WriteLine("DirectoryNotFoundException {0}", dnfe.Message); return; } try { // we skip the header, so we read first line without soring it reader.ReadLine(); } catch (NullReferenceException nre) { Console.WriteLine("No reader created, wrong path to file {0}", nre.Message); return; } catch (IOException io) { Console.WriteLine("No reader created, wrong path to file {0}", io.Message); return; } try { while (!reader.EndOfStream) { String line = reader.ReadLine(); if(line != null && line.Trim().Count() > 0) { hr.Payslip payslip = new hr.Payslip(line); this.payslips.add(payslip); } } } catch (NullReferenceException nre) { Console.WriteLine("Null reference: {0}", nre.Message); return; } catch (IOException io) { Console.WriteLine("IOException: {0}", io.Message); return; } }
private void readFile() { StreamReader reader = null; try { reader = new StreamReader(File.OpenRead(inputPayslipsFilePath)); } catch (DirectoryNotFoundException dnfe) { // it's ok, we don't have payslips yet. Console.WriteLine("DirectoryNotFoundException {0}", dnfe.Message); return; } try { // we skip the header, so we read first line without soring it reader.ReadLine(); } catch (NullReferenceException nre) { Console.WriteLine("No reader created, wrong path to file {0}", nre.Message); return; } catch (IOException io) { Console.WriteLine("No reader created, wrong path to file {0}", io.Message); return; } try { while (!reader.EndOfStream) { String line = reader.ReadLine(); if (line != null && line.Trim().Count() > 0) { hr.Payslip payslip = new hr.Payslip(line); this.payslips.add(payslip); } } } catch (NullReferenceException nre) { Console.WriteLine("Null reference: {0}", nre.Message); return; } catch (IOException io) { Console.WriteLine("IOException: {0}", io.Message); return; } }