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

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -