I have a sample program I'm playing with to learn a bit about JAVA. In the code below I have variables named 'file1' and 'file2' which are defined with a filenames 'file1.txt' and file2.txt respectively.
So when the program executes it looks for these files in the current directory. However, if I want to change these values to 'c:\file1.txt' and 'c:\ttmsapps\file2.txt' then I can't compile the program.
Would someone be able to show me in the code below how to specify a fully qualified filename? I'd certainly appreciate seeing the example.
import java.io.File;
import java.lang.Object;
import java.util.Date;
import java.text.Format;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class CompareFileDates {
public static void main(String[] args) {
String fileStatus = " ";
String file1 = "file1.txt";
String file2 = "file2.txt";
long date1 = 0;
long date2 = 0;
String finalDate1 = null;
String finalDate2 = null;
boolean file1Exists = (new File(file1)).exists();
boolean file2Exists = (new File(file2)).exists();
if (file1Exists) {
// Get the timestamp from file 1 and format it
date1 = (new File(file1)).lastModified();
Date newDate1 = new Date(date1);
DateFormat df = new SimpleDateFormat();
finalDate1 = df.format(newDate1);
}
else {
// File or directory does not exist
fileStatus = file1 + " does not exist. ";
}
...more