wangflood

精心维护一个技术blog,为了工作,也是爱好。

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  14 Posts :: 19 Stories :: 8 Comments :: 0 Trackbacks
我依然记得,曾经在听马士兵的J2SE的课程时,讲到regex时,有个方法叫"lookat",一向温和的马兄大怒,说SUN这个后知后觉的土鳖,这个名字取得多么垃圾。这个的人还混在sun里面,可以想见sun里面有多少这样的货色。又一年,sun被oracle收购,我大惊马士兵的预见性
后来我在读<<thinking in java>>时,发现Bruce,也在骂SUN。居然骂的话和马士兵一样
这么当然是马士兵抄袭了。技术员也就这么点乐。无语。。。。。。
不要相信那谁谁的。只穿一手鞋,我后来想。似乎此话也引自马士兵,不知马士兵引自谁的。
从研究源码开始吧。。。。。。
/**
 * 
 
*/
package com.wang.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.nio.channels.Channel;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

/**
 * 
@author Sam Wang
 * 
@since Mar 22, 2011
 
*/
public class TestSystem {

    
public static void main(String[] args) throws IOException {

        
// java居然可以打印错误。很少用到。Console下是红色的。估计java.util.logger是在其上包装的。
        System.err.println("err");
        
// 得到系统的环境。
        Map<String, String> envs = System.getenv();
        Set
<Entry<String, String>> sets = envs.entrySet();
        
for (Iterator<Entry<String, String>> iterator = sets.iterator(); iterator
                .hasNext();) {
            Entry
<String, String> entry = (Entry<String, String>) iterator
                    .next();
            System.out.println(entry.getKey().toLowerCase() 
+ ":"
                    
+ entry.getValue().toLowerCase());

        }
        
// 得到系统的Properties,大致的打印情况和getenv()差不多。
        Properties props = System.getProperties();
        System.out.println(props);

        
// 安全管理,神马玩艺。
        SecurityManager man = System.getSecurityManager();
        
// 对于特定的数字,打印的HashCode是一样的。
        
// 有时间再了解了解HashCode
        System.out.println(System.identityHashCode(0));// 19621457

        
// 这个Channel就是java.nio里面的。用作流处理的一类的东西的。
        
// 大致上和Input,System.io相关。
        Channel channel = System.inheritedChannel();
        
// 得到系统以long形式表示的当前时间。
        long time = System.nanoTime();
        System.out.println(time);
        Calendar c 
= Calendar.getInstance();
        c.setTimeInMillis(time);
        System.out.println(c.getTime());

        
// 不太常见,表示不理解
        System.runFinalization();

        
// System.err的包装。
        System.setErr(new PrintStream(new File("err.txt")));
        System.err.println(
"我犯错了。");
        System.setOut(
new PrintStream(new File("out.txt")));
        System.out.println(
"turn console to out.txt");

        
// System.in的包装。
        System.setIn(new FileInputStream("film.txt"));
        InputStreamReader isr 
= new InputStreamReader(System.in);
        BufferedReader br 
= new BufferedReader(isr);
        String str 
= "";
        
while ((str = br.readLine()) != null) {
            System.out.println(str);
        }

        Properties prop 
= new Properties();
        
// prop.load(new FileReader("test.properties"));
        prop.loadFromXML(new FileInputStream("prop.xml"));
        
// 这个也没什么用,得到系统配置,然后由系统设到一个prop.xml中。
        
// 其实也可以手动做。
        
// 有些人就是怀疑系统(JVM)是不是能给我们做更多的事。
        
// 其实系统不完美。
        System.setProperties(prop);
        Properties props2 
= System.getProperties();
        System.out.println(props2);

        
// 见名知义。这个方法参数我都不想填了。
        
// Sytem类肯定是java开发api时最先想到要开发的类了。
        
// 这个方法放在System里面
        
// 而不是在Arrays里面。是个历史遗留问题。
        
// System.arraycopy(src, srcPos, dest, destPos, length)

    }
}




posted on 2011-03-30 17:52 wangflood 阅读(296) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: