<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    zhyiwww
    用平實的筆,記錄編程路上的點點滴滴………
    posts - 536,comments - 394,trackbacks - 0

    This example implements a method that reads the entire contents of a file into a byte array.


    ?// Returns the contents of the file in a byte array.

    				
    						
    								    public static byte[] getBytesFromFile(File file) throws IOException {
    InputStream is = new FileInputStream(file);

    // Get the size of the file
    long length = file.length();

    // You cannot create an array using a long type.
    // It needs to be an int type.
    // Before converting to an int type, check
    // to ensure that file is not larger than Integer.MAX_VALUE.
    if (length > Integer.MAX_VALUE) {
    // File is too large
    }

    // Create the byte array to hold the data
    byte[] bytes = new byte[(int)length];

    // Read in the bytes
    int offset = 0;
    int numRead = 0;
    while (offset < bytes.length
    && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
    offset += numRead;
    }

    // Ensure all the bytes have been read in
    if (offset < bytes.length) {
    throw new IOException("Could not completely read file "+file.getName());
    }

    // Close the input stream and return bytes
    is.close();
    return bytes;
    }



    |----------------------------------------------------------------------------------------|
                               版權聲明  版權所有 @zhyiwww
                引用請注明來源 http://m.tkk7.com/zhyiwww   
    |----------------------------------------------------------------------------------------|
    posted on 2006-06-13 12:05 zhyiwww 閱讀(478) 評論(0)  編輯  收藏 所屬分類: code demo -java
    主站蜘蛛池模板: 日韩视频免费在线观看| 久久精品一本到99热免费| 久久精品国产亚洲麻豆| 伊人久久免费视频| 国产亚洲日韩在线三区| ssswww日本免费网站片| 红杏亚洲影院一区二区三区| 在线视频网址免费播放| 亚洲日韩av无码| 青青操免费在线观看| 亚洲国产精品久久久久| 99在线热视频只有精品免费| 亚洲成人黄色在线| 色妞WWW精品免费视频| 暖暖在线视频免费视频| 狠狠色伊人亚洲综合成人| 少妇太爽了在线观看免费视频 | 亚洲国产日韩在线视频| 中文字幕av免费专区| 亚洲AV无码一区二区二三区软件| 污视频在线观看免费| 亚洲一级特黄特黄的大片 | 五月婷婷亚洲综合| 精品国产污污免费网站入口| 亚洲an天堂an在线观看| 免费国产成人高清在线观看网站| 男人的天堂av亚洲一区2区| 亚洲伊人久久成综合人影院| 久久久久久国产精品免费免费男同| 亚洲福利视频一区二区三区| 日韩免费在线观看| A毛片毛片看免费| 国产成人精品日本亚洲专区6| 天堂亚洲免费视频| 免费人成在线观看网站| 羞羞视频在线观看免费| 亚洲一本一道一区二区三区| 亚洲欧洲精品国产区| 狠狠色伊人亚洲综合成人| 国产亚洲av片在线观看18女人| 国产午夜免费福利红片|