实现程序解压文件

    技术2022-05-13  39

    import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class CmdRuner extends Thread { private InputStream in = null; private OutputStream out = null; private Process process = null; public void run() { try { process = Runtime.getRuntime().exec("cmd"); } catch (Exception e) { e.printStackTrace(); System.out.println("程序出现无法控制的异常,请检查"); return; } int len; byte[] bytes = new byte[1024]; String temp; while (true) { try { in = process.getInputStream(); out = process.getOutputStream(); len = in.read(bytes); if (len <= 0) { sleep(1000); continue; } temp = new String(bytes, 0, len); System.out.println(temp); } catch (Exception e) { e.printStackTrace(); return; } } } public void input(String inputString) throws IOException { if (out != null) { out.write(inputString.getBytes()); out.flush(); } } public void 运行dos命令(String 盘符, String 路径, String 命令) throws IOException, InterruptedException { try { process = Runtime.getRuntime().exec("cmd"); out = process.getOutputStream(); } catch (Exception e) { e.printStackTrace(); System.out.println("程序出现无法控制的异常,请检查"); return; } int len; byte[] bytes = new byte[1024]; String temp; input(盘符 + "\n"); input("cd " + 路径 + "\n"); input(命令 + "\n"); input("rem 8897654334 \n"); while (true) { try { in = process.getInputStream(); len = in.read(bytes); if (len <= 0) { sleep(1000); continue; } temp = new String(bytes, 0, len); System.out.println(temp); if (temp.indexOf("8897654334") >= 0) { break; } } catch (Exception e) { e.printStackTrace(); return; } } } public static void main(String[] args) throws IOException, InterruptedException { CmdRuner cmdRuner = new CmdRuner(); // cmdRuner.运行dos命令("d:", // "D://正式工作//优质游戏//CS反恐精英之半条命","rmdir /S /Q fankong_K506"); // cmdRuner.运行dos命令("d:", // "D://正式工作//优质游戏//CS反恐精英之半条命","md fankong_K506"); // cmdRuner.运行dos命令("d:", "D://正式工作//优质游戏//CS反恐精英之半条命", "C://Program Files//WinRAR//WinRAR.exe/x fankong_K506.jar fankong_K506//"); // // cmdRuner.运行dos命令("d:", // "D://正式工作//优质游戏//CS反恐精英之半条命","copy fankong_K506.jar .//fankong_K506//"); cmdRuner.运行dos命令("e:", "E://qqgame", "copy 111.jpg aaa"); // cmdRuner.start(); // Thread.sleep(1000); // cmdRuner.input("type c;//eng000.txt/n"); // cmdRuner.input("cd"); // cmdRuner.input("cd D://工作//技术类项目//商务合作项目//安装盘//wspTest/n"); // cmdRuner.input("java -cp ./wspTest.jar udpWap.wspTest4 10.14.183.119 // 8521 8521/n"); // // Thread.sleep(1000); // cmdRuner.input("dir/n"); } }   package sharesoft; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class CmdRuner extends Thread { private InputStream in = null; private OutputStream out = null; private Process process = null; public void run() { try { process = Runtime.getRuntime().exec("cmd"); } catch (Exception e) { e.printStackTrace(); System.out.println("程序出现无法控制的异常,请检查"); return; } int len; byte[] bytes = new byte[1024]; String temp; while (true) { try { in = process.getInputStream(); out = process.getOutputStream(); len = in.read(bytes); if (len <= 0) { sleep(1000); continue; } temp = new String(bytes, 0, len); System.out.println(temp); } catch (Exception e) { e.printStackTrace(); return; } } } public void input(String inputString) throws IOException { if (out != null) { out.write(inputString.getBytes()); out.flush(); } } public void 运行dos命令(String 盘符, String 路径, String 命令) throws IOException { try { process = Runtime.getRuntime().exec("cmd"); out = process.getOutputStream(); } catch (Exception e) { e.printStackTrace(); System.out.println("程序出现无法控制的异常,请检查"); return; } int len; byte[] bytes = new byte[1024]; String temp; input(盘符+"/n"); input("cd "+路径+"/n"); input(命令+"/n"); input("rem 8897654334 /n"); while (true) { try { in = process.getInputStream(); len = in.read(bytes); if (len <= 0) { sleep(1000); continue; } temp = new String(bytes, 0, len); System.out.println(temp); if(temp.indexOf("8897654334")>=0){ break; } } catch (Exception e) { e.printStackTrace(); return; } } } public static void main(String[] args) throws IOException, InterruptedException { CmdRuner cmdRuner = new CmdRuner(); // cmdRuner.运行dos命令("d:", "D://正式工作//优质游戏//CS反恐精英之半条命","rmdir /S /Q fankong_K506"); // cmdRuner.运行dos命令("d:", "D://正式工作//优质游戏//CS反恐精英之半条命","md fankong_K506"); // cmdRuner.运行dos命令("d:", "D://正式工作//优质游戏//CS反恐精英之半条命", "/"C://Program Files//WinRAR//WinRAR.exe/" x fankong_K506.jar fankong_K506//"); // // cmdRuner.运行dos命令("d:", "D://正式工作//优质游戏//CS反恐精英之半条命","copy fankong_K506.jar .//fankong_K506//"); cmdRuner.运行dos命令("d:", "D://test","copy 流程图片.rar rrr"); //cmdRuner.start(); //Thread.sleep(1000); // cmdRuner.input("type c;//eng000.txt/n"); //cmdRuner.input("cd"); // cmdRuner.input("cd D://工作//技术类项目//商务合作项目//安装盘//wspTest/n"); // cmdRuner.input("java -cp ./wspTest.jar udpWap.wspTest4 10.14.183.119 // 8521 8521/n"); // //Thread.sleep(1000); // cmdRuner.input("dir/n"); }


    最新回复(0)