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

📄 cd.java

📁 用command模式写的一个简单的java 程序
💻 JAVA
字号:
/*******************************************************************************  Filename    :cd.java
*  Description :cd command
*
*  Author      :xunzy
*
*  History     :2004-02-16   Created******************************************************************************/import java.util.Vector;import java.io.*;class cd implements Command {	public void execute(File currentDir, Vector v) throws CommandException {	if (FileSystemShell.getCurrentDir() == null)	throw new CommandException(new Exception(), "No current dir");	else if (v.isEmpty())	throw new CommandException(new Exception(), "No name specified");		// get args[0] and throw away the other args	else {	String name = (String)v.firstElement();	if(name.indexOf("/")>=0){	    throw new CommandException(new Exception(), "Name error!!!\nCouldn't change to dir: " + name);	}		if (name.equals("..")) {	  String path=FileSystemShell.getParentDir();	  FileSystemShell.setCurrentDir(path);          	  int ind=path.lastIndexOf("\\"); 	  if(path.substring(0,ind).endsWith(":")){	    FileSystemShell.setParentDir(path.substring(0,ind+1));	  }	  else	    FileSystemShell.setParentDir(path.substring(0,ind));	  //System.out.println(FileSystemShell.getParentDir());	  FileSystemShell.setCurrentFile(new File(FileSystemShell.getCurrentDir()));	  System.out.println("Current Dir now :" + FileSystemShell.getCurrentDir());	}	else if (name.equals(".")) {	  System.out.println("Current Dir now :" + FileSystemShell.getCurrentDir());	}	else if (name.equals("\\")) {	  FileSystemShell.setCurrentDir(FileSystemShell.getDefaultDir());	  FileSystemShell.setParentDir(FileSystemShell.getDefaultDir());	  FileSystemShell.setCurrentFile(new File(FileSystemShell.getCurrentDir()));	  System.out.println("Returning to default directory");	}	else {	  char ch=':';	  String dir;	  if(FileSystemShell.getCurrentDir().endsWith("\\"))	    dir=FileSystemShell.getCurrentDir()+name;	  else	    dir=FileSystemShell.getCurrentDir()+"\\"+name;	  File c = new File(dir);	  if(!c.exists()){	    throw new CommandException(new Exception(), "Couldn't change to dir: " + name);	  }	  //String dirNew=dir.replaceAll("/","\\");	  int ind=dir.lastIndexOf("\\"); 	  FileSystemShell.setParentDir(dir.substring(0,ind));	  //FileSystemShell.setParentDir(FileSystemShell.getCurrentDir());	  FileSystemShell.setCurrentDir(dir);	  FileSystemShell.setCurrentFile(c);	  System.out.println("Current Dir now :" + FileSystemShell.getCurrentDir());	}    }  }      public void help() { System.out.println("Usage: cd [name]"); }}

⌨️ 快捷键说明

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