Exemple:
File file = File("C:\\Dossier_111\\fichier.txt");Il va afficher le chemin complet : "C:\\Dossier_111\\fichier.txt".
System.out.println("Chemin: " + file.getAbsolutePath());
Dans la plupart des cas, vous aurez besoin de récupérer seulement le chemin sans le nom du fichier en utilisant des fonctions comme substring() et lastIndexOf().
File file = File("C:\\Dossier111\\fichier.txt");Exécution:
String absolutePath = file.getAbsolutePath();
String filePath = absolutePath.
substring(0,absolutePath.lastIndexOf(File.separator));
System.out.println("Chemin: " + filePath);
C:\\Dossier111
Ressources:
tutorialspoint - Java.io.File.getAbsolutePath() Method
Commentaires (0)
Laisser un commentaire
Connectez-vous pour commenter
Rejoignez la discussion et partagez vos connaissances avec la communauté
Chargement des commentaires...