1:获取文件信息的方法。
public class FileMethod {
public static void main(String[] args) {
File file = new File("E:\\wxy\\20-21vue\\npm.txt");
System.out.println(file.getPath());//获取路径,等于file.toString
System.out.println(file.toString());//等于getPath
System.out.println(file.getName());//返回文件或文件夹的结尾。
System.out.println(file.length());//返回文件的大小字节
File file2 = new File("npm.txt");
System.out.println(file2.getAbsolutePath());//获取当前路径下的绝对路径
}
}
E:\wxy\20-21vue\npm.txt
E:\wxy\20-21vue\npm.txt
npm.txt
152
E:\workspace\project0005\npm.txt
2:判断文件信息的方法
public class FileMethod2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("E:\\wxy\\20-21vue\\npm.txt");
if(file.exists()) {
System.out.println(file.isDirectory());
System.out.println(file.isFile());
}
}
}
3:创建文件,文件夹方法:
public class FileMethod3 {
//文件如果不存在,就会创建返回true,如果已经存在了,就不会创建,返回false。createNewFile只能创建文件
public