我是如何在另一个 java 程序中启动一个程序的新手!我不知道怎么称呼它。第一个问题是我必须在一个新线程中进行吗?第二个问题是如何调用新程序。我要调用的程序是“wondershaper”。我使用 ubuntu 12.04 运行这个程序并在命令行中编写。“sudo wondershaper eth0 10000 1000”。我如何在通用程序中编写它?我有一个服务器,我想处理它的速率!这就是我使用它的原因。所以我有一个多线程服务器,代码是
class Client extends Thread {
    private Socket connectionSocket;
    public Client(Socket c) throws IOException {
        connectionSocket = c;
    }
    public void run() {
        String path = "C:/pao/new2/";
        File folder = new File(path);
        File[] listOfFiles = folder.listFiles();
        try {
            String fileToSendStr = readFile();
            File fileToSend = null;
            for (File f : listOfFiles)
            {               
                if (f.getName().equals(fileToSendStr)) {
                    fileToSend = f;
                    break;
                }
            }
            //System.out.println("Connescting to Client to recieve the part " +fileToSendStr);
            if (fileToSend == null) {
            }
            System.out.println("Sending the chunk to Client " + fileToSendStr + "to the client: " +connectionSocket.getRemoteSocketAddress().toString());
            java.util.Date date= new java.util.Date();
             System.out.println(new Timestamp(date.getTime()));
            long length = fileToSend.length();
            byte [] longBytes = new byte[8];
            ByteBuffer bbuffer = ByteBuffer.wrap(longBytes);
            bbuffer.putLong(length);
            connectionSocket.getOutputStream().write(longBytes);
            BufferedOutputStream bout = new BufferedOutputStream(connectionSocket.getOutputStream());
            BufferedInputStream bain = new BufferedInputStream(new FileInputStream(fileToSend));
            byte buffer [] = new byte [1024];
            int i = 0;
            while((i = bain.read(buffer, 0, 1024)) >= 0){
                bout.write(buffer, 0, i);
            }
            System.out.println("chunk sended");
            java.util.Date date1= new java.util.Date();
             System.out.println(new Timestamp(date1.getTime()));
            bout.close();
            bain.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private String readFile() throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(
                connectionSocket.getInputStream()));
        return r.readLine();
    }
}
所以当我阅读客户端发送给我的 readFile 时。如果是速率字符串,则启动“wondershaper”并将速率放入“sudo wondershaper eth0 10000 速率”并启动程序