import java.io.*;
public class fileDemo{
public static void main(String[] args){
File file=new File("F:\\JavaeeWorkstation2\\Iostream\\src\\ceshi.txt");
File file2=new File("F:\\JavaeeWorkstation2\\Iostream\\src\\ceshi2.txt");
try {
file.createNewFile();
file2.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(file.getName());
System.out.println(file.getTotalSpace()/(1024*1024*1024)+"GB");
File filess=new File("F:\\JavaeeWorkstation2\\Iostream\\src");
File[] filename=filess.listFiles(new Filter());
System.out.println("txt文件有");
for(File s:filename){
System.out.println(s);
}
File[] files=filess.listFiles();
System.out.println("所有文件有");
for(File s:files){
System.out.println(s);
}
}
}
class Filter implements FilenameFilter{
@Override
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
if(dir!=null&&name.endsWith(".txt")){
return true;
}else{
return false;
}
}
}
public class fileDemo{
public static void main(String[] args){
File file=new File("F:\\JavaeeWorkstation2\\Iostream\\src\\ceshi.txt");
File file2=new File("F:\\JavaeeWorkstation2\\Iostream\\src\\ceshi2.txt");
try {
file.createNewFile();
file2.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(file.getName());
System.out.println(file.getTotalSpace()/(1024*1024*1024)+"GB");
File filess=new File("F:\\JavaeeWorkstation2\\Iostream\\src");
File[] filename=filess.listFiles(new Filter());
System.out.println("txt文件有");
for(File s:filename){
System.out.println(s);
}
File[] files=filess.listFiles();
System.out.println("所有文件有");
for(File s:files){
System.out.println(s);
}
}
}
class Filter implements FilenameFilter{
@Override
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
if(dir!=null&&name.endsWith(".txt")){
return true;
}else{
return false;
}
}
}