• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

            路漫漫,長修遠,我們不能沒有錢
            隨筆 - 173, 文章 - 0, 評論 - 257, 引用 - 0
            數據加載中……

            java執行外部指令,并接收中文結果

            package com.khan.util;


            import java.io.BufferedInputStream;
            import java.io.IOException;
            import java.io.InputStream;
            //import java.io.File;

            /**
            ?* <p>Title: </p>
            ?* <p>Description: </p>
            ?* <p>Copyright: Copyright (c) 2006</p>
            ?* <p>Company: </p>
            ?* @author not attributable
            ?* @version 1.0
            ?*/


            public class ExecCmd {

            ??? public ExecCmd() {

            ??? }


            ??? // read an input-stream into a String
            ??? public static String loadStream(InputStream in, String charset) throws IOException {
            ??????? int char_set_len = 2;
            ??????? if (null == charset) {
            ??????????? charset = "GBK";
            ??????? }

            ??????? if (charset.equals("utf8") || charset.equals("UTF8")
            ??????????? || charset.equals("utf-8") || charset.equals("UTF-8")) {
            ??????????? char_set_len = 3;
            ??????? }

            ??????? int ptr = 0;
            ??????? byte[] char_buff = new byte[char_set_len];
            ??????? in = new BufferedInputStream(in);

            ??????? StringBuffer buffer = new StringBuffer();
            ??????? while ((ptr = in.read()) != -1) {

            ??????????? if (ptr >= 0x80) { //中文處理
            ??????????????? char_buff[0] = (byte) ptr;
            ??????????????? for (int i = 1; i < char_set_len; i++) {
            ??????????????????? char_buff[i] = (byte) in.read();
            ??????????????????? if (char_buff[i] == -1) {
            ??????????????????????? break;
            ??????????????????? }
            ??????????????? }
            ??????????????? buffer.append(new String(char_buff, charset));
            ??????????????? continue;
            ??????????? }

            ??????????? buffer.append((char) ptr);
            ??????? }
            ??????? return buffer.toString();
            ??? }


            ??? static public void main(String[] args) {
            ??????? long l = 0;
            ??????? String str = "";
            ??????? String[] cmd1 = {"cmd.exe",
            ??????????????????????? "/c",
            ??????????????????????? "dir",
            ??????????????????????? "/b",
            ??????????????????????? "/s",?? "e:\\*.log"};
            ??????????????????????? //args[0] +"\\*.log"};

            ??????? String[] cmd = {"gawk",
            ?????????????????????? "-F,",
            ?????????????????????? //"\"END{print NR}\"",
            ?????????????????????? "\"END{print substr($1, 0, 8), NR}\"",
            ?????????????????????? "mo_pay.log"};
            ??????? //File dir = new File("D:\\Program Files\\gawk\\bin");

            ??????? try {
            ??????????? Process ps = Runtime.getRuntime().exec(cmd1);
            ??????????? String[] strs = loadStream(ps.getInputStream(), "GBK").split("\r\n");
            ??????????? System.err.print(loadStream(ps.getErrorStream(), "GBK"));
            ??????????? for (int i = 0; i < strs.length; i++) {
            ??????????????? cmd[3] = strs[i].trim();
            ??????????????? ps = Runtime.getRuntime().exec(cmd);
            ??????????????? str = loadStream(ps.getInputStream(), "GBK");
            ??????????????? str = str.substring(0, str.indexOf('\r'));

            ??????????????? l += Long.parseLong(str.split(" ")[1]);
            ??????????????? System.out.println(str);
            ??????????????? System.err.print(loadStream(ps.getErrorStream(), "GBK"));
            ??????????? }
            ??????????? System.out.println(l);
            ??????? } catch (IOException e) {
            ??????????? e.printStackTrace();
            ??????? }
            ??????? //System.out.println("執行完畢");
            ??? }

            }



            ? 這個代碼是我最近的一個project中,用來調用gawk的處理結果,并在web上顯示
            在web中顯示的部分就是jsp了.這個就沒有必要貼了,
            ? awk處理文本的效率確實不錯.

            posted on 2006-09-28 10:07 Khan 閱讀(1019) 評論(0)  編輯 收藏 引用 所屬分類: 跨平臺開發 、Java

            大伊人青草狠狠久久| 合区精品久久久中文字幕一区| 精品久久久噜噜噜久久久| 久久这里只有精品18| 久久久WWW免费人成精品| 久久天天躁夜夜躁狠狠躁2022| 欧洲成人午夜精品无码区久久| 欧美777精品久久久久网| 久久91精品国产91| 一本大道加勒比久久综合| 久久婷婷是五月综合色狠狠| 国产欧美久久久精品| 亚洲精品国产美女久久久| 久久综合五月丁香久久激情| 97r久久精品国产99国产精| 中文精品久久久久人妻| 精品国产热久久久福利| 久久ww精品w免费人成| 久久强奷乱码老熟女网站| 久久久久国产一区二区| 精品久久久久久久久中文字幕| 久久91精品国产91久| 久久国产午夜精品一区二区三区| 国产精品99久久99久久久| 蜜桃麻豆WWW久久囤产精品| 久久亚洲国产精品123区| 99久久国产综合精品五月天喷水| 久久久久人妻精品一区| 亚洲欧美日韩精品久久亚洲区 | 狠狠色噜噜狠狠狠狠狠色综合久久| 久久久精品波多野结衣| 99久久国产免费福利| 久久综合丁香激情久久| 99久久精品影院老鸭窝| 狠狠色婷婷综合天天久久丁香| 久久亚洲精精品中文字幕| 青草国产精品久久久久久| 久久亚洲AV成人出白浆无码国产| 7777精品久久久大香线蕉| AV无码久久久久不卡蜜桃| 日本欧美久久久久免费播放网|