Added numberOfLines function
This commit is contained in:
parent
96c0742b5e
commit
61f3968aaf
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user