So I have a program that I'm working on to format and query google for lat and long coordinates based on locations I have in a CSV file. The program is by no means efficient and I honestly do not care as long as it formats an output formatted correctly that I can use for a XML file. Google has a limit on queries so I decided to store previous queries in a basic text file and then check using buffer reader to see if the line.contains(companyname) but it never matches. I print out both the string that is being compared to the contains and the line and they are identical in print out but lengths are different by 1. I'm assuming there are some hidden characters or something that is throwing of the contains() method.
Sample output:
Below is the two important methods to this process.
public static void writeCordFile(String company, String lat, String log) {
try {
System.out.println("writing to /Users/ASheridan/Downloads/cord" +"data:"+company + "lat: " + lat + "log" + log);
FileWriter writer = new FileWriter("/Users/ASheridan/Downloads/cord", true);
//writer.write(company + " lat: " + lat + " log: " + log);
writer.write(company+" ");
writer.write("\r\n");
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean checkIfCordinatesExist(String companyName) {
BufferedReader br = null;
String cordStorage = "/Users/ASheridan/Downloads/cord";
String lineCord = "";
try {
br = new BufferedReader(new FileReader(cordStorage));
System.out.println("CHECKING THE FULL FILE FOR MATCHES");
int i=0;
while ((lineCord = br.readLine()) != null) {
System.out.println(i);
i++;
System.out.println("compare to: "+lineCord.compareTo(companyName));
System.out.println("line length: "+lineCord.length());
System.out.println("company length: "+companyName.length());
if (lineCord.toLowerCase().contains(companyName.toLowerCase())) {
System.out.println("Existing Cordinates for " + cordStorage + " found");
return true;
}
else {
System.out.println("Result for " + companyName +"not found in line:" + lineCord);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return false;
}