设为首页 加入收藏

TOP

Java IO 文件拷贝功能的实现(五)
2018-03-28 09:05:59 】 浏览:830
Tags:Java 文件 拷贝 功能 实现
ode>b[off]</code> is the first
    * byte written and <code>b[off+len-1]</code> is the last byte written
    * by this operation.
    * <p>
    * The <code>write</code> method of <code>OutputStream</code> calls
    * the write method of one argument on each of the bytes to be
    * written out. Subclasses are encouraged to override this method and
    * provide a more efficient implementation.
    * <p>
    * If <code>b</code> is <code>null</code>, a
    * <code>NullPointerException</code> is thrown.
    * <p>
    * If <code>off</code> is negative, or <code>len</code> is negative, or
    * <code>off+len</code> is greater than the length of the array
    * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
    *
    * @param      b    the data.
    * @param      off  the start offset in the data.
    * @param      len  the number of bytes to write.
    * @exception  IOException  if an I/O error occurs. In particular,
    *            an <code>IOException</code> is thrown if the output
    *            stream is closed.
    */
    public void write(byte b[], int off, int len) throws IOException {
        if (b == null) {
            throw new NullPointerException();
        } else if ((off < 0) || (off > b.length) || (len < 0) ||
                  ((off + len) > b.length) || ((off + len) < 0)) {
            throw new IndexOutOfBoundsException();
        } else if (len == 0) {
            return;
        }
        for (int i = 0 ; i < len ; i++) {
            write(b[off + i]);
        }
    }


同样的,这个方法也是对 write( int b ) 方法的封装。


另外我加了可以测试耗费时间的一个小功能,原理很简单,就是使用 currentTimeMillis() 方法,源码如下:


    /**
    * Returns the current time in milliseconds.  Note that
    * while the unit of time of the return value is a millisecond,
    * the granularity of the value depends on the underlying
    * operating system and may be larger.  For example, many
    * operating systems measure time in units of tens of
    * milliseconds.
    *
    * <p> See the description of the class <code>Date</code> for
    * a discussion of slight discrepancies that may arise between
    * "computer time" and coordinated universal time (UTC).
    *
    * @return  the difference, measured in milliseconds, between
    *          the current time and midnight, January 1, 1970 UTC.
    * @see    java.util.Date
    */
    public static native long currentTimeMillis();


可以看到,这个方法的返回值是当前时间到197

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android 自定义ToolBar详细使用 下一篇Java中的Number和Math类简单介绍

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目