The package output specifies the absolute path to the file; import java.io.file;/* * Requirements: Please put the "E:\\java language" directory in the end of all Java files in the absolute path to the output in the console. * * Analysis: * A: Package directory * B: Get the file array of all files or folders in this directory * C: Traverse the file array to get each file Object * D: Determine if the file object is a folder * Yes: Go back to B * No: Continue to determine whether to end with. Java * Yes: the absolute path to the output of the file * No: Ignore it */public class Filepathdemo {public static void main (string[] args) {//package directory file Srcfile = new Fil E ("E:\\java language");//recursive implementation of getalljavafilepaths (Srcfile);} private static void Getalljavafilepaths (file srcfile) {//Get file array for all files or folders in this directory file[] Filearray = Srcfile.listfiles () ;//traverse the file array to get each file object for (file File:filearray) {//To determine if the file object is a folder if (File.isdirectory ()) {getalljavafilepaths ( file);//Recursive call}else {//continue to determine if the. Java ends if (file.getname (). EndsWith (". Java")) {//outputs the absolute path of the file System.out.println ( File.getabsolutepath ());}}}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java code Implementation output specifies the absolute path of a file ending in. java