Beispiel:
File file = File("C:\\Dossier_111\\fichier.txt");Es wird der vollständige Pfad angezeigt: "C:\\Dossier_111\\fichier.txt".
System.out.println("Pfad: " + file.getAbsolutePath());
In den meisten Fällen müssen Sie nur den Pfad ohne den Dateinamen abrufen, indem Sie Funktionen wie substring() und lastIndexOf() verwenden.
File file = File("C:\\ Datei111\\fichier.txt");Runtime:
String absolutePath = file.getAbsolutePath();
String filePath = absolutePath.
substring(0,absolutePath.lastIndexOf(File.separator));
System.out.println("Pfad: " + filePath);
C:\\Folder111
Resources:
tutorialspoint - Java.io.File.getAbsolutePath() Methode
Commentaires (12)
Connectez-vous pour commenter
Rejoignez la discussion et partagez vos connaissances avec la communauté
Excellent tutoriel !
N'hésitez pas si vous avez des questions.