public final class System {
    private System() { }
    public final static PrintStream out = getConsoleOutput();
    private static PrintStream getConsoleOutput() {
	return new PrintStream(new SystemOutputStream());
    }
    public final static PrintStream err = out;
    public static native long currentTimeMillis();

    public static native void arraycopy(Object src, int src_position,
                                        Object dst, int dst_position,
                                        int length);

    public static native int identityHashCode(Object x);

    public static String getProperty(String key) {
        if (key == null) {
            throw new NullPointerException("key can't be null");
        }
        if (key.equals("")) {
            throw new IllegalArgumentException("key can't be empty");
        }
        return getProperty0(key);
    }
    private native static String getProperty0(String key);
    public static void exit(int status) {
        Runtime.getRuntime().exit(status);
    }
    public static void gc() {
        Runtime.getRuntime().gc();
    }
}
  1. System.out使用SystemOutputStream。我们看看它是怎样的:
  2. public class SystemOutputStream extends OutputStream {
        synchronized public void write(int c) throws IOException {
            putchar((char)c);
        }
        private static native void putchar(char c);
    }
     可以看到跟C里面的putchar是一样的,实际上是调用C的putchar。
  3. System是静态类。提供系统的便利方法。
  4. System没有输入流。注意手机并没有控制台,像window下的dos或者linux的bash shell。没有该方面的功能。
  5. 当程序运行在手机上,调用System.out.println()是不会被显示的。只仅仅调试的时候才有控制台。但该控制台只能输出。
评论
发表评论

您还没有登录,请登录后发表评论

Azi
搜索本博客
存档
最新评论