byte 1字节 8bit位 取值范围:-2^7~2^7-1
short 2字节 16bit位 取值范围:-2^15~2^15-1
int 4字节 32bit位 取值范围:-2^31~2^31-1
long 8字节 64bit位 取值范围:-2^63~2^63-1
常用的File对象的API
File file = new File("E:\\..."); file.exists(); file.mkdir(); file.mkdirs(); file.createNewFile(); file.delete(); file.isDirectory(); file.isFile(); File file2 = new File("e:\\javaio\\日记1.txt"); File file2 = new File("e:\\javaio","日记1.txt"); System.out.println(file);//file.toString()的内容 file.getAbsolutePath(); file.getName(); file.getParent();
递归目录
public static void listDirectory(File dir) throws IOException{
if(!dir.exists()){
throw new IllegalArgumentException("目录" + dir + "不存在");
}
if(!dir.isDirectory()){
throw new IllegalArgumentException(dir + "不是一个目录");
}
-------------------------------------------------
//返回的是字符串数组 直接子的名称 不包含子目录下的内容
String[] filename = dir.list();
for (String string : filename) {
System.out.println(dir + "\\" + string);
}
-------------------------------------------------
//返回的是直接子目录(文件)的对象
File[] files = dir.listFiles();//返回的是字符串数组 直接子的名称 不包含子目录下的内容
if(files!=null && files.length>0){
for (File file : files) {
if(file.isDirectory()){
//递归
listDirectory(file);
}else{
System.out.println(file);
}
}
}