Example:
File file = File("C:\\Dossier_111\\fichier.txt");It will display the full path: "C:\\Dossier_111\\fichier.txt".
System.out.println("Path: " + file.getAbsolutePath());
In most cases, you will need to retrieve only the path without the file name using functions like substring() and lastIndexOf().
File file = File("C:\\ File111\\fichier.txt");Runtime:
String absolutePath = file.getAbsolutePath();
String filePath = absolutePath.
substring(0,absolutePath.lastIndexOf(File.separator));
System.out.println("Path: " + filePath);
C:\\Folder111
Resources:
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...