Hello Java experts here is my question. I currently have a code that runs some queries and outputs the data into a csv file. It currently outputs it into my desktop and saves the files.
as you can see
//csv printer
PrintWriter pw = null;
try {
pw = new PrintWriter(new BufferedWriter(new FileWriter("C:\\Users\\JChoi\\Desktop\\new Date().getTime() + data.csv")));
} catch (Exception e) {
System.out.println("I could not open the output csv file, see stacktrace below:");
e.printStackTrace();
}
although it printed the file, the file just came out to say "new Date().getTime()data.csv"
i guess im missing a step in setting the date and time. ultimately i want to get it so that when i run this file, i will get a new csv file with today's date and current time on the file. Thanks
EDIT: SOLVED
Date dNow = new Date( );
SimpleDateFormat timeStamp =
new SimpleDateFormat ("yyyy-MM-dd");
//csv printer
PrintWriter pw = null;
try {
pw = new PrintWriter(new BufferedWriter(new FileWriter("C:\\Users\\JChoi\\Desktop\\google api csv outputs\\" + timeStamp.format(dNow) +"_data.csv")));
}
thanks all