Added new code to check binary file
This commit is contained in:
parent
f32ef9c56e
commit
33a8eaa4c5
@ -9,15 +9,18 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.nio.charset.CodingErrorAction;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class fileProcessor {
|
||||
|
||||
public static String readFirstLine(String thisFile) throws IOException {
|
||||
File file = new File(thisFile);
|
||||
Boolean isValid = validFile(thisFile);
|
||||
|
||||
if ( !isValid )
|
||||
{
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (file.exists()) {
|
||||
@ -28,7 +31,9 @@ public class fileProcessor {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static Boolean getFile(String myFile) {
|
||||
@ -54,7 +59,9 @@ public class fileProcessor {
|
||||
FileReader fileReader = new FileReader(myFile);
|
||||
BufferedReader reader = new BufferedReader(fileReader);
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
line = line.replaceAll("(?m)^\\s+|\\s+$", "");
|
||||
sb.append(line);
|
||||
}
|
||||
reader.close();
|
||||
@ -75,6 +82,33 @@ public class fileProcessor {
|
||||
return returnString;
|
||||
}
|
||||
|
||||
public static boolean fileHasText(String thisFile, String word) throws FileNotFoundException
|
||||
{
|
||||
boolean flag = false;
|
||||
Scanner sc2 = new Scanner(new FileInputStream(thisFile));
|
||||
while(sc2.hasNextLine()) {
|
||||
String line = sc2.nextLine();
|
||||
if( line.indexOf(word) != -1 )
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static boolean stringHasText(String line, String regex) throws FileNotFoundException
|
||||
{
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(line);
|
||||
|
||||
int matches = 0;
|
||||
while ( matcher.find() )
|
||||
{
|
||||
matches++;
|
||||
}
|
||||
return (matches > 0);
|
||||
}
|
||||
|
||||
public static boolean validFile(String thisFile)
|
||||
{
|
||||
Path path = Paths.get(thisFile);
|
||||
|
Loading…
x
Reference in New Issue
Block a user