From 61f3968aafe10d820a9e3519512b9d3cfd0ddd1a Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Sat, 4 Jan 2025 08:31:45 -0500 Subject: [PATCH] Added numberOfLines function --- src/com/belkast/soap/fileProcessor.java | 30 +++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/com/belkast/soap/fileProcessor.java b/src/com/belkast/soap/fileProcessor.java index a3786ba..392b3fb 100644 --- a/src/com/belkast/soap/fileProcessor.java +++ b/src/com/belkast/soap/fileProcessor.java @@ -73,19 +73,41 @@ public class fileProcessor { } public static Boolean validFile(String myFile) { + Path path = Paths.get(myFile); try (Reader reader = Files.newBufferedReader(path)) { int c = reader.read(); - if (c == 0xfeff) { - System.out.println("File starts with a byte order mark."); - } else if (c >= 0) { + if (c == 0xfeff) + { +/* System.out.println("File starts with a byte order mark."); */ + } + else if (c >= 0) + { reader.transferTo(Writer.nullWriter()); } } catch (CharacterCodingException e) { return false; } catch (IOException e) { - throw new RuntimeException(e); + return false; +// throw new RuntimeException(e); } return true; } + + public static long numberOfLines(String fileName) + { + Path path = Paths.get(fileName); + long lines = 0; + + try + { + lines = Files.lines(path).count(); + } + catch (IOException e) + { + e.printStackTrace(); + } + + return lines; + } } \ No newline at end of file