题目描述:编写一个命令行工具,能够像Windows提供的cmd命令一样,可以执行各种常见的命令,如dir,move等
代码如下:(功能有待完善)
阅读(65) | 评论(0) | 转发(0) |
<script>window._bd_share_config={"common":{"bdsnskey":{},"bdtext":"","bdmini":"2","bdminilist":false,"bdpic":"","bdstyle":"0","bdsize":"16"},"share":{}};with(document)0[(getelementsbytagname('head')[0]||body).appendchild(createelement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new date()/36e5)];</script>
代码如下:(功能有待完善)
点击(此处)折叠或打开
- import java.io.*;
- import java.util.Scanner;
- public class cmd {
- public static void showAllFiles(String path)
- {
- File newFile = new File(path);
- if (newFile.exists())
- {
- File[] fileList = newFile.listFiles();
- if (fileList.length == 0)
- {
- System.out.println("文件夹是空的");
- }
-
- for (File file:fileList)
- {
- if (file.isFile())
- {
- System.out.println("文件名"+file.getAbsolutePath());
- }
- else{
- System.out.println("路径名"+file.getAbsolutePath());
- showAllFiles(file.getAbsolutePath());
- }
- }
- }
- else
- System.out.println("文件不存在");
- }
- public static void copyFile(String dst,String src) throws IOException
- {
- FileOutputStream fos = null;
- FileInputStream fis = null;
- fos = new FileOutputStream(dst+"\\"+src.substring(src.lastIndexOf('\\')+1));
- fis = new FileInputStream(src);
- int hasRead = 0;
- byte[] bbuf = new byte[1024];
- while ((hasRead = fis.read(bbuf)) > 0)
- {
-
- fos.write(bbuf,0,hasRead);
- }
-
- }
- public static void copy(String dst,String src) throws IOException
- {
- File newFile = new File(src);
- File[] fileList = newFile.listFiles();
- //File dstFile = new File(dst+"//"+newFile.getName());
- if (newFile.isFile())
- {
-
- copyFile(dst,src);
- }
- else
- {
- File dstFile = new File(dst+"//"+newFile.getName());
- if (!dstFile.exists())
- {
- dstFile.mkdirs();
- }
- for (File file:fileList)
- {
- if (file.isFile())
- copyFile(dstFile.getAbsolutePath(),file.getAbsolutePath());
- else
- copy(dstFile.getAbsolutePath(),file.getAbsolutePath());
- }
- }
- }
- public static void main(String[] args) throws IOException {
- InputStreamReader reader = new InputStreamReader(System.in);
- BufferedReader br = new BufferedReader(reader);
- String line = null;
- while ((line = br.readLine()) != null)
- {
- //System.out.println(line[0]);
- String ss[] = line.split(" ");//用Scanner无法处理\n
- // char c = ss[0].charAt(0);
- if (ss.length > 3)
- {
-
- return;
- }
- if (ss[0].equals("move"))
- {
-
- copy(ss[1],ss[2]);
- System.out.println("OK");
- }
- /* else if ((c =='c' || c == 'C') ||
- (c == 'd' || c == 'd'))
-
- {
- System.out.println(c+"\\>");
-
- }*/
- else if (ss[0].equals("dir"))//文件名不能有空格
- {
- System.out.println(ss[1]);
- showAllFiles(ss[1]);
-
- }
- else
- {
- System.out.println(ss[0]);
- System.out.println("hi");
- }
- }
-
-
-
- }
- }
- /*import java.io.*;
-
- public class cmd
- {
- public static void main(String args[]) throws IOException
- {
- System.out.print("请输入回车键继续...");
- if (new InputStreamReader(System.in).read() == 13)
- {
- //Do something here;
- }
- }
- }*/
相关热门文章
- Tomcat 6 配置SSI
- 让Resin支持shtml(SSI)- 静...
- tomcat + ssi
- ASP JavaScript Lessons(8-14)
- JDK1.6官方下载_JDK6官方下载_...
给主人留下些什么吧!~~
评论热议