java开发项目,目录结构大家一般怎么划分?

java开发项目,目录结构大家一般怎么划分?,第1张

public class DirectoryPrinter {

private static List<String>list = new ArrayList<String>()

private static int floor = 0

public static void printDirectory(File root) {

if (root.isFile()) {

System.out.println(getPreString(floor, root) + root.getName())

} else {

System.out.println(getPreString(floor, root) + root.getName())

floor++

File[] files = root.listFiles()

setLast(files)

for (File file : files) {

printDirectory(file)

}

floor--

}

}

private static String getPreString(int floor, File file) {

if (floor == 0)

return ""

String preString = "ㄴ"

for (int i = 1i <floori++) {

file = file.getParentFile()

if (list.contains((file.getAbsolutePath() + file.getName())))

preString = " " + preString

else

preString = "|" + preString

}

return preString

}

private static void setLast(File[] files) {

if (files.length != 0) {

int last = 0

for (int i = 0i <files.lengthi++) {

if (files[i].isDirectory())

last = i

}

list.add(files[last].getAbsolutePath() + files[last].getName())

}

}

public static void main(String[] args) {

DirectoryPrinter.printDirectory(new File("D://workspace//JavaTest"))

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11511302.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存