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

📄 catalogshow.java

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

public class CatalogShow
{
  private String fullPath; //要显示文件的完整路径
  public CatalogShow(){
    fullPath="/";
  }

  public CatalogShow(String path){
    fullPath=path;
  }
  //设置完整路径
  public void setPath(String path){
    fullPath=path;
  }
  //得到完整路径
  public String getPath(){
    return fullPath;
  }
  //解析字符串,将所有的空格用"%20"代替
  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 String dirUp(String path){
    String result="";
    File dir=new File(path);
    result=dir.getParent();
    return decodeString(result);
  }
  //得到当前目录下的所有文件的列表
  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 + -