• <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

            久久久人妻精品无码一区| 欧美日韩精品久久免费| 精品亚洲综合久久中文字幕| 久久人人爽爽爽人久久久| 亚洲欧美精品伊人久久| 少妇被又大又粗又爽毛片久久黑人 | 东京热TOKYO综合久久精品| 伊人久久大香线蕉影院95| 亚洲伊人久久成综合人影院| 7777久久亚洲中文字幕| 性欧美大战久久久久久久| 无码久久精品国产亚洲Av影片| 久久免费国产精品一区二区| 久久国产一片免费观看| 久久综合噜噜激激的五月天| 久久精品国产色蜜蜜麻豆| 国产精品久久久久天天影视| 精品久久久久久久国产潘金莲 | 精品国产综合区久久久久久| 国内精品久久久久久久久电影网 | 久久精品草草草| 亚洲午夜久久久影院伊人| 久久亚洲高清综合| 亚洲午夜久久久精品影院| 久久久精品国产sm调教网站| 国产aⅴ激情无码久久| 亚洲国产成人久久笫一页| 一级做a爰片久久毛片16| 国产精品久久毛片完整版| 久久丫精品国产亚洲av不卡| 久久99这里只有精品国产| 女同久久| 欧美午夜A∨大片久久| 欧美日韩中文字幕久久久不卡| 久久国产精品国语对白| 国内精品久久久久久久coent | 久久久久亚洲精品无码蜜桃| 午夜精品久久久久久中宇| 久久久久久曰本AV免费免费| 精品国产乱码久久久久久呢| 亚洲AV无码久久精品狠狠爱浪潮 |