Added trim to all user input
This commit is contained in:
parent
2a233bc5d3
commit
33dc0592f3
@ -15,8 +15,9 @@ 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);
|
||||
String myFile = thisFile.trim();
|
||||
File file = new File(myFile);
|
||||
boolean isValid = validFile(myFile);
|
||||
|
||||
if ( !isValid )
|
||||
{
|
||||
@ -36,23 +37,25 @@ public class fileProcessor {
|
||||
|
||||
}
|
||||
|
||||
public static Boolean getFile(String myFile) {
|
||||
if (myFile == null) {
|
||||
public static Boolean getFile(String thisFile) {
|
||||
if (thisFile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
File thisFile = new File(myFile);
|
||||
if (thisFile.exists()) {
|
||||
String myFile = thisFile.trim();
|
||||
File checkFile = new File(myFile);
|
||||
if (checkFile.exists()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static long getSize(String myFile)
|
||||
public static long getSize(String thisFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
String myFile = thisFile.trim();
|
||||
File varFile = new File (myFile);
|
||||
return varFile.length();
|
||||
}
|
||||
@ -62,9 +65,10 @@ public class fileProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public static String replaceInFile(String myFile, Map hashMap) {
|
||||
File thisFile = new File(myFile);
|
||||
if (!thisFile.exists()) {
|
||||
public static String replaceInFile(String thisFile, Map hashMap) {
|
||||
String myFile = thisFile.trim();
|
||||
File checkFile = new File(myFile);
|
||||
if (!checkFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@ -97,8 +101,9 @@ public class fileProcessor {
|
||||
|
||||
public static boolean fileHasText(String thisFile, String word) throws FileNotFoundException
|
||||
{
|
||||
String myFile = thisFile.trim();
|
||||
boolean flag = false;
|
||||
Scanner sc2 = new Scanner(new FileInputStream(thisFile));
|
||||
Scanner sc2 = new Scanner(new FileInputStream(myFile));
|
||||
while(sc2.hasNextLine()) {
|
||||
String line = sc2.nextLine();
|
||||
if( line.indexOf(word) != -1 )
|
||||
@ -124,7 +129,8 @@ public class fileProcessor {
|
||||
|
||||
public static boolean validFile(String thisFile)
|
||||
{
|
||||
Path path = Paths.get(thisFile);
|
||||
String myFile = thisFile.trim();
|
||||
Path path = Paths.get(myFile);
|
||||
boolean result = true;
|
||||
long total = 0;
|
||||
InputStreamReader isr = null;
|
||||
@ -138,7 +144,7 @@ public class fileProcessor {
|
||||
decoder.onMalformedInput(CodingErrorAction.REPORT);
|
||||
|
||||
try {
|
||||
isr = new InputStreamReader(new FileInputStream(thisFile), decoder);
|
||||
isr = new InputStreamReader(new FileInputStream(myFile), decoder);
|
||||
while ((chars = isr.read(buf)) >= 0)
|
||||
total += chars;
|
||||
} catch (CharacterCodingException ex) {
|
||||
@ -156,9 +162,11 @@ public class fileProcessor {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static long numberOfLines(String fileName)
|
||||
public static long numberOfLines(String thisFile)
|
||||
{
|
||||
Path path = Paths.get(fileName);
|
||||
String myFile = thisFile.trim();
|
||||
|
||||
Path path = Paths.get(myFile);
|
||||
long lines = 0;
|
||||
|
||||
try
|
||||
|
@ -21,7 +21,7 @@ public class userVerify
|
||||
while (true)
|
||||
{
|
||||
System.out.print(varPrompt);
|
||||
varFileName = myObj.nextLine();
|
||||
varFileName = myObj.nextLine().trim();
|
||||
File thisFile = new File(varFileName);
|
||||
boolean isValidFile = fileProcessor.validFile(varFileName);
|
||||
if ( thisFile.exists() && isValidFile )
|
||||
|
Loading…
x
Reference in New Issue
Block a user