java文件管理类

import java.io.*;

public class FileManager {
	public File file;
	public String fileDir;
	
	public FileManager(String dir) 
	{
		fileDir = dir;
		file = new File(dir);
	}
	
	public static boolean isFile(String fileDir)
	{
		boolean result = false;
		File file = new File(fileDir);
        result = file.exists()? true : false;
		
		return result;
	}
	
	public boolean createDir() 
	{
		boolean result = false;
		if(!file.isDirectory() && !file.exists())
		{
			file.mkdir();
			result = true;
		}
		
		return result;
	}
	
	public boolean creatFile() throws IOException
	{
		boolean result = false;
		if(!file.isFile() && !file.isDirectory() && !file.exists()) 
		{
			file.createNewFile();
			result = true;
		}
		
		return result;
	}
	
	public boolean deleteFile() 
	{
		boolean result = false;
		if(file.exists() && file.isFile()) 
		{
			file.delete();
			result = true;
		}
		
		return result;
	}
	
	public boolean deleteDir() 
	{
		boolean result = false;
		if(file.exists() ) 
		{
			File[] temp = file.listFiles();
			for(File f : temp) 
			{
				System.out.println(f.getName());
				FileManager fManager = new FileManager(this.fileDir + "/" + f.getName());
				if(fManager.file.isDirectory()) 
				{
					fManager.deleteDir();
				}
				else 
				{
					fManager.file.delete();
				}
			}
		file.delete();
		result = true;
		}
		
		return result;
	}
	
}

未完待续。。。

你可能感兴趣的:(java,F#)