⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 catalogoperate.java

📁 jsp数据库编程入门
💻 JAVA
字号:
package test;
import java.io.*;

public class CatalogOperate
{
  private String fullPath;
  public CatalogOperate()
  {
    fullPath="c:";
  }

  public CatalogOperate(String path)
  {
    fullPath=path;
  }

  public String getPath()
  {
    return fullPath;
  }

  public String decodeString(String src)
  {
    String des=null;
    if (src!=null){
      des="";
      for (int i=0;i<src.length();i++)
      {
        if (src.charAt(i)==' '){
        
          des+="%20";
        }else{
          des+=src.charAt(i);
        }
      }
    }
    return des;
  }

  public String addPath(String fileName)
  {
    String result="";
    if (fullPath.charAt(fullPath.length()-1)=='\\')
    {
      result=fullPath+fileName;
    }else
    {
      result=fullPath+'\\'+fileName;
    }
    return decodeString(result);
  }

  public void setPath(String path)
  {
      fullPath=path;
  }

  public String dirUp(String path)
  {
    String result="";
    File dir=new File(path);
    result=dir.getParent();
    return decodeString(result);
  }

  public boolean copyFile(String fileName)
  {
    return true;
  }

  public boolean pasteFile(String fileName)
  {
    return true;
  }

  public boolean cutFile(String fileName)
  {
    return true;
  }
  
  //删除文件或目录
  public boolean deleteFile(String path)
  {
    try{
      File file=new File(path);
      return file.delete();
    }catch(Exception e)
    {
      e.printStackTrace();
      return false;
    }
  }

  //在当前目录下新建一个子目录
  public boolean newDir(String dirName)
  {
    try{
      File file=new File(fullPath+'\\'+dirName);
      return file.mkdirs();
    }catch(Exception e){
      e.printStackTrace();
      return false;
    }
  }

  //在当前目录下新建一个文件
  public boolean newFile(String fileName)
  {
    try{
      File file = new File(fullPath+'\\'+fileName);
      return file.createNewFile();
    } catch (IOException e) 
    {
      e.printStackTrace();
      return false;
    }
  }

  public static File[] listRoot()
  {
    return File.listRoots();
  }

  public File[] listFiles() 
  {
    File dir=new File(fullPath);
  	String[] ss = dir.list();
  	if (ss == null)
	    return null;
    int n = ss.length;
  	File[] fs = new File[n];
	for(int i = 0; i < n; i++) 
	{
	    fs[i] = new File(dir.getPath(), ss[i]);
  	}
	  return fs;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -