I'm trying to wrte some data to a file using the following code:
There are 90,000 lines in the input file so there should be 90,000 in the output, but there isn't, there's only 89,772. I have absolutely no idea why its missing the end off.
I've got several other programs which use very similar code working with file sizes from 1MB to 500MB, so file size isn't the problem. I've also tried writing a .dat instead of a .txt but same result. I've also tested it with multiple input files but it gives the same result. I've also checked there isn't anything funny going on with line 89,772 in the input file (missing line, extra characters etc) but it all looks fine. I've also debugged the code and it's reading all the way up to 90,000 lines and its even executing the "out.println("-" + lon + tempLon + lat + tempLat + "0");" line with the very last line in the input file so its executing the code correctly by the looks of it, it just doesn't want to output everything to the text file.
Any ideas whats going wrong?
Thanks.
Code:
public static void buildFile(int lat, int lon) throws IOException{
String tempLat;
String tempLon;
String line;
if (lat <10)
temp = "G:\\South America 300(1)\\N0" + lat + "W0" + lon +".txt";
else
temp = "G:\\South America 300(1)\\N" + lat + "W0" + lon +".txt";
File inFile = new File("North.txt");
FileReader input = new FileReader(inFile);
BufferedReader bufRead = new BufferedReader(input);
File outFile = new File(temp);
PrintWriter out = new PrintWriter(new FileWriter(outFile));
line = bufRead.readLine(); // Read first line
while (line != null){
tempLon = line.substring(3,10);
tempLat = line.substring(11,18);
out.println("-" + lon + tempLon + lat + tempLat + "0");
line = bufRead.readLine();
}
}
There are 90,000 lines in the input file so there should be 90,000 in the output, but there isn't, there's only 89,772. I have absolutely no idea why its missing the end off.
I've got several other programs which use very similar code working with file sizes from 1MB to 500MB, so file size isn't the problem. I've also tried writing a .dat instead of a .txt but same result. I've also tested it with multiple input files but it gives the same result. I've also checked there isn't anything funny going on with line 89,772 in the input file (missing line, extra characters etc) but it all looks fine. I've also debugged the code and it's reading all the way up to 90,000 lines and its even executing the "out.println("-" + lon + tempLon + lat + tempLat + "0");" line with the very last line in the input file so its executing the code correctly by the looks of it, it just doesn't want to output everything to the text file.
Any ideas whats going wrong?
Thanks.