发布新日志

  • shell里面的条件判断和循环

    2008-12-31 13:13:02

    1 条件判断  if
    if test -f "$1"
    then
    echo "$1 is a file"
    elif test -d "$1"
    then
    (cd "$1";pwd;echo "$1 is a directory")
    else
    echo "$1 is neither a file or a directory"
    fi
    注意 每个if 后面都有一个then ,
    第二个条件用 elif ,
    结尾用fi
    2 条件判断case
    case $1 in
    (*.c)
    echo "c file" ;;
    (*.txt)
    echo "txt file" ;;
    (*)
    echo "unknown file";;
    esac
    注意结尾要用esac , case后执行要用两个;;

    3 while循环

    i=0;
    sum=0;
     
    while true
    do
    i=`expr $i + 1`
    sum=`expr $sum + $i`
    if [ $i = "100" ]
    then break
    fi
    done
    echo $i $sum
    注意 while后要有do , done , 执行表达式用用`` , 数学运算要用expr , if后面跟表达式要用[], 而且里面的句子一定要跟[和] 有空格。
    还有while跟until的区别
    until [ $i = "100" ]   和  while [ $i != "100" ]
    注意不能用< >, 这里是输入输出的意思。
    大于小于用 -gt -lt 表示

    4 for循环


  • 准备辞职找工作

    2008-12-31 12:59:53

      已经跟经理提出离职了,趁还在公司的这段时间整理一些在linux下工作积累的经验。
  • build.xml 学习

    2007-09-27 10:51:21

    <?xml version = "1.0" encoding="GB2312" ?>
    <project default = "main" basedir = "." >
     <property name = "srcpath" value = "sdkongkong"/>
     <property name = "classpath" value = "build/classes"/>
     <target name = "init">
       <mkdir dir = "${classpath}"/>
     </target>
     <target name = "main" depends = "init">
       <javac srcdir = "${srcpath}" destdir = "${classpath}"/>
     </target>
     <target name = "clean" descrīption = "clean old class">
       <delete dir ="${classpath}"/>
     </target>
    </project>
  • 获取一个url的内容.

    2007-03-30 23:49:36

    WebPageReader.java

    package sdkongkong;
       import java.net.URL;
       import java.net.MalformedURLException;
       import java.net.URLConnection;
       import java.io.IOException;
       import java.io.BufferedReader;
       import java.io.InputStreamReader;

       public class WebPageReader {

          private static URLConnection connection;

          private static void connect( String urlString ) {
            try {
              URL url = new URL(urlString);
              connection = url.openConnection();
              System.out.println(connection.getClass());
            } catch (MalformedURLException e){
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }

          private static void readContents() {
            BufferedReader in = null;
            try {
              in = new BufferedReader(
                new InputStreamReader(
                  connection.getInputStream()));

              String inputLine;
              while (
                (inputLine = in.readLine()) != null) {
                System.out.println(inputLine);
              }
            } catch (IOException e) {
              e.printStackTrace();
            }
          }

          public static void main(String[] args) {
            if (args.length != 1) {
              System.err.println("usage: java WebPageReader " + "<url>");
              System.exit(0);
            }
            connect(args[0]);
            readContents();
          }
       }

     

    使用方法,java WebPageReader + url(http://www.sina.com)

Open Toolbar