2017.03.14_File类和enum枚举类_小程序

来源:互联网 发布:手机磁力链接播放软件 编辑:程序博客网 时间:2024/04/29 16:18
 浑浑噩噩学了一段时间JAVA,时间一长,许多东西都被时间遗落。最近决心好好学习JAVA,又恐心止于口,便于此记录自己的学习吧。
今天学的内容很少,主要是File类和enum枚举类。
学习的两个小程序摘录如下:
import java.io.*;
//用递归获取目录的树状图
public class FlieList{
public static void main(String args[]) {
File f = new File("E:/myeclipse/pratical/hehe");
System.out.println(f.getName());
tree(f,1);
}
private static void tree(File f, int level) { //level为目录级别
String prestr = "";
for(int i=0; i<level; i++) {
prestr += " ";
}

File[] chiles = f.listFiles();
for(int i=0; i<chiles.length; i++) {
System.out.println(prestr + chiles[i].getName());
if(chiles[i].isDirectory()) {
tree(chiles[i], level+1);
}
}
}
}

public class Enum {
public enum yourname{hehe, haha, xixi}; //限定只能选择三者其中之一。
public static void main(String args[]) {
yourname m = yourname.xixi;
switch (m) {
case hehe:
System.out.println("hehe");
break;
case xixi:
System.out.println("xixi");
break;
default:
System.out.println("default");
}
System.out.println(m);
}
}

2017.03.14
0 0