Simulate touch command with Java

后端 未结 7 1364
太阳男子
太阳男子 2021-02-03 17:33

I want to change modification timestamp of a binary file. What is the best way for doing this?

Would opening and closing the file be a good option? (I require a solution

7条回答
  •  走了就别回头了
    2021-02-03 17:58

    Here's a simple snippet:

    void touch(File file, long timestamp)
    {
        try
        {
            if (!file.exists())
                new FileOutputStream(file).close();
            file.setLastModified(timestamp);
        }
        catch (IOException e)
        {
        }
    }
    

提交回复
热议问题