2017.03.14_File类和enum枚举类_小程序
来源:互联网 发布:手机磁力链接播放软件 编辑:程序博客网 时间:2024/04/29 16:18
浑浑噩噩学了一段时间JAVA,时间一长,许多东西都被时间遗落。最近决心好好学习JAVA,又恐心止于口,便于此记录自己的学习吧。今天学的内容很少,主要是File类和enum枚举类。
//用递归获取目录的树状图
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);
}
}
}
学习的两个小程序摘录如下:
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);
}
}
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
- 2017.03.14_File类和enum枚举类_小程序
- 71_常用类_file类_打印目录树状结构_递归算法_(枚举补充)
- Java enum枚举类使用小技巧
- Java基础_常用类_File
- 枚举 _类集对Enum的支持
- 【枚举】_类集对Enum的支持笔记
- 【枚举】_类集对Enum的支持笔记
- JDK5新特性_通过enum实现枚举类
- 枚举 类 enum
- 枚举类enum
- Enum枚举类
- enum枚举类
- enum枚举类
- Java枚举类 enum
- JAVA 枚举类 Enum
- 枚举类 Enum 使用
- enum枚举类
- Enum枚举类
- unity3d中实现相机的跟随
- CppPrimer笔记 Chapter14 重载运算与类型转换
- 动态库的链接和链接选项-L,-rpath-link,-rpath
- LeetCode 11. Container With Most Water
- List基础用法汇总
- 2017.03.14_File类和enum枚举类_小程序
- 派
- 选择排序
- 无常之无常
- CppPrimer笔记 Chapter15 面对对象程序设计
- 217. Contains Duplicate
- 时间换算
- windows cmd命令行显示下面的文件
- POJ 2955 Brackets(区间dp)