java - Create filename with date and time -


i have inherited java source code logs binary data file. below section creating file. do, instead of calling file data.file call file hour-min-dd-mm-yy-data.file.

please help, suggestions welcome.

public void run() {     inputstream inputstream;     bufferedinputstream bufferedreader = null;     fileoutputstream writer = null;      try {         inputstream = btsocket.getinputstream();         byte[] buffer = new byte[1024];               bufferedreader = new bufferedinputstream(inputstream);         file gpxfile = new file(folder, "data.file");         writer = new fileoutputstream(gpxfile, true);          long totalbytes = 0;         arraylist<byte> pendingbytes = new arraylist<byte>(); 

you're looking simpledateformat class: https://docs.oracle.com/javase/7/docs/api/java/text/simpledateformat.html

try this:

simpledateformat dt = new simpledateformat("yyyy-mm-dd_hh-mm-ss");  date date = new date(); string filename = dt.format(date); 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -