Setting the file creation timestamp in Java
I know that setting the creation timestamp does not exist in Java because Linux does not, but is there any way to set the file (Windows) creation timestamp in Java? Here I made a basic modification to the timestamp editor
import java.io.*; import java.util.*; import java.text.*; import javax.swing.*; public class chdt{ static File file; static JFrame frame = new JFrame("Input a file to change"); public static void main(String[] args) { try{ final JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false); //BufferedReader bf = new BufferedReader(new InputStreamReader(system.in)); //System.out.println("Enter file name with extension:"); //String str = bf.readLine(); JOptionPane.showMessageDialog(null,"Input a file to change."); frame.setSize(300,200); frame.setVisible(true); int retVal = fc.showOpenDialog(frame); if (retVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); frame.setVisible(false); } else { JOptionPane.showMessageDialog(null,"3RR0RZ! You didn't input a file."); System.exit(0); } //System.out.println("Enter last modified date in 'dd-mm-yyyy-hh-mm-ss' format:"); //String strDate = bf.readLine(); String strDate = JOptionPane.showInputDialog("Enter last modified date in 'dd-mm-yyyy-hh-mm-ss' format:"); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss"); Date date = sdf.parse(strDate); if (file.exists()){ file.setLastModified(date.getTime()); JOptionPane.showMessageDialog(null,"Modification is successful!"); } else{ JOptionPane.showMessageDialog(null,"File does not exist! Did you accidentally it or what?"); } } catch(Exception e){ e.printStackTrace(); JOptionPane.showMessageDialog(null,"3RR0RZ"); } } }
Solution
I believe you have the following options:
Find a tool that can be called from the command line Then you can interact with it from your Java code. > The following links in MSDN file times show how any tool works – pay special attention to the functions GetFileTime and setfiletime
I guess you'll be lucky here:) search for these features on Google and I found a post here This answer (not acceptable) to how to discover a file's creation time with Java seems to do what you want to use JNA and the above methods If so, please ask this answer again:)
Please don't mind the title. It has a way to set the creation time I hope you'll try to make it work