how to write a filename

here is my problem I want my Log Files Filename to be created with respect to the Current Date..e.g. say today is May 24,2007....then the created log file will display in c;/ as c:/2007-05-24.csv....then if I'll use the application say in June 05..another file will be created c:/2007-06-05.

BufferedWriter out = new BufferedWriter(new FileWriter("c:/Filename.csv", true));

out.write(" AutoArchive-Process Started at ");

Calendar c = new GregorianCalendar();

out.write(c.getTime().toString());

out.close();

[558 byte] By [ryshi1264a] at [2007-11-27 5:20:02]
# 1
Forget Calendar. Use SimpleDateFormat.[url= http://www.javaalmanac.com/egs/java.text/FormatDate.html]Formatting a Date Using a Custom Format[/url][url= http://www.javaalmanac.com/egs/java.text/ParseDate.html]Parsing a Date Using a Custom Format[/url]
jverda at 2007-7-12 11:43:44 > top of Java-index,Java Essentials,Java Programming...
# 2

You can do this:

SimpleDateFormat bartDateFormat =

new SimpleDateFormat("yyyy-MM-dd");

Date date = new Date();

String dateValue=(bartDateFormat.format(date));

String fileName="C:\\"+dateValue+".csv";

BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));

Sorry didn't see the previous post

Message was edited by:

diptaPB

diptaPBa at 2007-7-12 11:43:44 > top of Java-index,Java Essentials,Java Programming...
# 3

I encountered an error in this part upon compilation

Date date = new Date();

nit:

deps-jar:

Compiling 1 source file to C:\Documents and Settings\Administrator\Archive\build\classes

C:\Documents and Settings\Administrator\Archive\src\ArchLog.java:176: cannot find symbol

symbol : constructor Date()

location: class java.sql.Date

Date date = new Date();

ryshi1264a at 2007-7-12 11:43:44 > top of Java-index,Java Essentials,Java Programming...
# 4
It should be java.util.Date not java.sql.Date... Check your import statement.What JDK version you are using?Message was edited by: diptaPB
diptaPBa at 2007-7-12 11:43:44 > top of Java-index,Java Essentials,Java Programming...
# 5
my JDK is 1.6
ryshi1264a at 2007-7-12 11:43:44 > top of Java-index,Java Essentials,Java Programming...
# 6
I told you to check the import statement also.. it should not be java.sql.Date.. it will be java.util.Date
diptaPBa at 2007-7-12 11:43:44 > top of Java-index,Java Essentials,Java Programming...
# 7

thank you so much ..got it....one more question though how will i display the contents of this file and file directory in a jTestArea or JTable...let's say it will display the content of "c:/AutoArchive2007-05-24.csv" in a jTextarea or jTable....

-

user:jeffAutoArchive-Process Started at Thu May 24 15:41:54 GMT+08:00 2007

and ended at Thu May 24 15:41:54 GMT+08:00 2007

--

ryshi1264a at 2007-7-12 11:43:44 > top of Java-index,Java Essentials,Java Programming...