?? catalogoperate.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;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -