阅读Java代码的的一些收获


1. StringTokenizer 怎么用 ?

 String   str   =   "127.0.0.1";          
          StringTokenizer   st   =   new   StringTokenizer(str,   ".",   false);  
         //如果最后一个参数为true,则返回值中包括"."    
          while(st.hasMoreTokens()){  
                  int   j;  
                  String   token   =   st.nextToken();  
                  j   =   Integer.parseInt(token);  
                  System.out.println(j);  
                  }  
          }  
   
  st就是StringTokenizer,nextToken返回下一个token

2.System.getProperties() 得到什么。。。

import   java.util.Enumeration;  
  import   java.util.Properties;  
   
  public   class   SystemInfo   {  
   
  public   static   void   main(String[]   args)   {  
  Properties   systemProperties=System.getProperties();  
  Enumeration   enums=systemProperties.propertyNames();  
  while(enums.hasMoreElements()){  
  String   key=(String)enums.nextElement();  
  System.out.println(key+"="+systemProperties.getProperty(key));  
  }  
  }  
  }  

System.getProperties()可以得到Java运行环境的一些基本属性  
   
  你要添加的话,可以实例化一个Properties对象,然后set

  --   listing   properties   --  
  java.runtime.name=Java(TM)   2   Runtime   Environment,   Stand...  
  sun.boot.library.path=D:/j2sdk1.4.1_03/jre/bin  
  java.vm.version=1.4.1_03-b02  
  java.vm.vendor=Sun   Microsystems   Inc.  
  java.vendor.url=http://java.sun.com/  
  path.separator=;  
  java.vm.name=Java   HotSpot(TM)   Client   VM  
  file.encoding.pkg=sun.io  
  user.country=CN  
  sun.os.patch.level=Service   Pack   3  
  java.vm.specification.name=Java   Virtual   Machine   Specification  
  java.runtime.version=1.4.1_03-b02  
  java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment  
  java.endorsed.dirs=D:/j2sdk1.4.1_03/jre/lib/endorsed  
  os.arch=x86  
  line.separator=  
   
  java.vm.specification.vendor=Sun   Microsystems   Inc.  
  user.variant=  
  java.naming.factory.url.pkgs=org.apache.naming  
  os.name=Windows   2000  
  sun.java2d.fontpath=  
  java.library.path=D:/j2sdk1.4.1_03/bin;.;D:/WINNT/Syste...  
  java.specification.name=Java   Platform   API   Specification  
  java.class.version=48.0  
  java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFac...  
  os.version=5.0  
  user.home=D:/Documents   and   Settings/administrator  
  user.timezone=Asia/Shanghai  
  catalina.useNaming=true  
  java.awt.printerjob=sun.awt.windows.WPrinterJob  
  file.encoding=GBK  
  java.specification.version=1.4  
  catalina.home=E:/Program   Files/JBuilder7/jakarta-to...  
  user.name=chenyan  
  java.class.path=D:/Program   Files/Apache   Tomcat   4.0/bi...  
  java.naming.factory.initial=org.apache.naming.java.javaURLContext...  
  axis.enableListQuery=true  
  java.vm.specification.version=1.0  
  sun.arch.data.model=32  
  java.home=D:/j2sdk1.4.1_03/jre  
  java.specification.vendor=Sun   Microsystems   Inc.  
  user.language=zh  
  awt.toolkit=sun.awt.windows.WToolkit  
  java.vm.info=mixed   mode  
  java.version=1.4.1_03  
  java.ext.dirs=D:/j2sdk1.4.1_03/jre/lib/ext  
  sun.boot.class.path=D:/j2sdk1.4.1_03/jre/lib/rt.jar;D:/j2...  
  java.vendor=Sun   Microsystems   Inc.  

//往system properties 里set新的对象
Properties   p=System.getProperties();  
          p.setProperty("just   test","Ok");//

另: 用什么类和函数可以得到jvm的版本呢?
直接用  
  String   s   =   System.getProperty("java.vm.version");  
  s   就是jvm的版本.字符串格式.  
  如果输出结果可能类似如下格式(和jvm版本有关).  
  1.5.0_05-b05

3.in.read()返回的什么?

From   JDK   API   Document:  
  public   int   read()  
                    throws   IOExceptionReads   a   byte   of   data   from   this   input   stream.   This   method   blocks   if   no   input   is   yet   available.  
  Overrides:  
  read   in   class   InputStream  
  Returns:  
  the   next   byte   of   data,   or   -1   if   the   end   of   the   file   is   reached.  
  Throws:  
  IOException   -   if   an   I/O   error   occurs.  
  -----------------------------------------------------------------  
  read   return   a   byte   code   read   from   stream.   That's   why   using   write(c)   can   write   a   correct   character   to   the   outputstream.  
  You   can   use   if(c   ==   '/n')   to   check   if   the   character   is   a   return   carrier.  

使用:
int ch = in.read ();
    while (true) {
        switch (ch)    {
        case -1:
        return;

        case '#':
        if (srcFile == null) {
            do {
            ch = in.read ();
            }
            while ((ch >= 0) && (ch != '/n') && (ch != '/r'));
        }
        else {
            bufindx = 0;
            for (ch = in.read (); (ch >= 0) && (ch != '/n') && (ch != '/r'); ch = in.read ()) {
            buf = appendToArray (buf, bufindx++, ch);
            }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值