Exemples Java - Afficher la date de dernière modification d'un fichier spécifié sur l'hôte
L'exemple suivant montre comment afficher la date de dernière modification d'un fichier spécifié sur l'hôte :
Fichier Main.java
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.text.SimpleDateFormat;
public class Main {
public static void main(String[] argv) throws Exception {
URL u = new URL("http://127.0.0.1/test/test.html");
URLConnection uc = u.openConnection();
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
uc.setUseCaches(false);
long timestamp = uc.getLastModified();
System.out.println("heure de dernière modification du fichier test.html :" + ft.format(new Date(timestamp)));
}
}
La sortie de l'exécution du code ci-dessus est :
test.html 文件最后修改时间 :2018-09-06 10:06:04Autres extensions
Exemples Java