posts - 3, comments - 15, trackbacks - 0, articles - 26
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          deleteDirectoryorFile Getpath.path() TestCmd()

          Posted on 2005-06-24 15:59 morcble的blog 閱讀(291) 評論(0)  編輯  收藏 所屬分類: Java

          //刪除文件  無論a是文件還是文件夾
          public class file {
           public static void deleteDirectoryorFile(java.io.File a){//全路徑
            if (a.isFile()){
             a.delete();
            }
            else{
             java.io.File[] files = a.listFiles();
             for(int i= 0 ;i<files.length;i++){
              deleteDirectoryorFile(files[i]);
             }
             a.delete();
            }
           }
          }

           

           

           

           


          **
           *
           * web-inf的相對路徑 調用方法 Getpath.path();
           */
          public class Getpath {
           private String path;

           private static Getpath s;//靜態單例模式

           public Getpath() {
            path = this.getClass().getResource("Getpath.class").getPath();
            path = path.substring(0, path.indexOf("WEB-INF"));
            path = path + "WEB-INF/";
           }

           public void setpath(String path) {
            this.path = path;
           }

           public String getpath() {
            return this.path;
           }

           public static String path() {
            if (s == null)
             s = new Getpath();
            return (s.getpath());
           }

           public static void main(String[] args) {

            System.out.println(Getpath.path());
           }
          }

           

           

          /**
          *
          * @author  Administrator
          */
          public class TestCmd {
              public TestCmd(){}
              public static void main(String args[]){
                  try {
                    Process process = Runtime.getRuntime().exec("cmd.exe  /c  start           // Process process = Runtime.getRuntime().exec("cmd.exe  /c  start  ping 10.5.2.19");  //調用Ping命令
                  }catch (Exception  e)
                  {
                      e.printStackTrace();
                      } 
                 
                }
              }

          主站蜘蛛池模板: 哈尔滨市| 黄平县| 连云港市| 华容县| 华安县| 尼勒克县| 巴马| 老河口市| 高碑店市| 堆龙德庆县| 永仁县| 安国市| 江西省| 洛阳市| 博白县| 察隅县| 水城县| 昌黎县| 禄劝| 道孚县| 易门县| 青神县| 房产| 永济市| 财经| 军事| 六枝特区| 五家渠市| 瑞丽市| 铅山县| 舟曲县| 原阳县| 游戏| 成武县| 长葛市| 东丽区| 江永县| 横山县| 青浦区| 沾化县| 崇阳县|