Interpreted Java - Set data and time

Hi,

I'd like to set the filename of my export file to include the current date and time so making it easy to identify the results of a particular session. My Java skills are weak (well, non-existent but I'm learning), but I assume it is something like:

out = new FileWriter( "my_file_name" + my_date_time + ".xml", true );

where [b]my_data_time[/b] is some form of date function (any suggestions, or even a pointer where to look for documentation).

rgds/alex

Interpreted Java - Set data and time

Calling the write data to file after each page is probably the best way to do it. In order to not get a separate file for each write you could set the file name in a script before the scraping session is run like this:

session.setVariable ("OUTPUT_FILE", "myfilename" + System.currentTimeMillis( ) + ".xml" );

and then for your file writer
out = new FileWriter( session.getVariable("OUTPUT_FILE"), true );

Bigger issues - when to call script

Well I think I've got a bigger problem.

At the moment I call my write to file script each time I get a matching record e.g. my session trawls through a list page and for each item it finds, it calls the details page and then calls my write to file script.

This means that the write to file script is called (file opened, data added, file closed) for each detail page. This seems to be very inefficient but I'm not sure from the tutorials how to hold all of the data in memory and then dump it out at the end which I'm sure would be much quicker. Any suggestions?

I found this out as I tried adding System.currentTimeMillis() to my file name and I got rather a large number of files as my script created a new file for each record.