java - Creating new text file using date and time as text file name -
can show me example code of how create new text file using date , time text file name. please show how save new text file in specific folder path in computer. try not working
file f = new file("d://filepath//clear.dat"); string filename = f.getname(); filename = filename+new java.util.date() +".dat"; system.out.println(filename);
first, date , time string
formatted correctly. can use simpledateformat
. , can use file(file, string)
constructor give file
correct folder. might use printstream(file)
print
something. , try-with-resources
statement clean-up. finally, put like
dateformat df = new simpledateformat("yyyymmddhhmmss"); file folder = new file("d://filepath"); file f = new file(folder, string.format("clear-%s.txt", df.format(new date()))); try (printstream ps = new printstream(f) { ps.println("hello, file!"); } catch (ioexception e) { e.printstacktrace(); }
Comments
Post a Comment