Java examples for File Path IO:File Attribute
Update any or all of the file's last modified time, last access time, and create time attributes
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.FileTime; public class Main { public static void main(String[] args) { Path path = Paths//from www . j ava2s .c om .get("D:\\folder0\\Java\\JDK7\\folder5\\code\\folder1\\folder2\\folder6","test.txt"); // update any or all of the file's last modified time, last access time, and create time attributes long time = System.currentTimeMillis(); FileTime fileTime = FileTime.fromMillis(time); try { Files.getFileAttributeView(path, BasicFileAttributeView.class).setTimes( fileTime, fileTime, fileTime); } catch (IOException e) { System.err.println(e); } } }