Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Core Java Code Examples

Getting and Setting the Modification Time of a File or Directory

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Getting and Setting the Modification Time of a File or Directory public static void main(String args[]){ try{ File file = new File("file.txt"); // Get the last modified time long modifiedTime = file.lastModified(); // 0L is returned if the file does not exist // Set the last modified time long newModifiedTime = System.currentTimeMillis(); boolean success = file.setLastModified(newModifiedTime); if (!success) { System.out.println("Operation failed"); } } catch (Exception ioe){ ioe.printStackTrace(); } }