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

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

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

    David.Turing's blog

     

    FileUtils

    /*
    ?*Copyright ? 2006 David.turing
    ?*Email: securex@163.com
    ?*QQ群:14966586
    ?*/
    package org.dev2dev.common;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;

    public class FileUtils {
    ??? // 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;
    ??? }
    ???
    ???
    ??? public static void main(String[] args) {

    ??
    ??File x=new File("115.txt");
    ??? try {
    ??FileOutputStream out=new FileOutputStream(x);
    ???? out.write("xxxxxxxxxxxx".getBytes());
    ???? out.flush();
    ???? out.close();
    ?} catch (FileNotFoundException e) {??
    ??e.printStackTrace();
    ?} catch (IOException e) {??
    ??e.printStackTrace();
    ?}
    ???
    ?}

    }

    posted on 2006-05-21 17:16 david.turing 閱讀(659) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(110)

    我參與的團隊

    隨筆分類(126)

    隨筆檔案(155)

    文章分類(9)

    文章檔案(19)

    相冊

    搜索

    積分與排名

    最新隨筆

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 一级毛片直播亚洲| 亚洲精品一二三区| 亚洲毛片基地日韩毛片基地| 亚洲人成网站在线在线观看| 中国一级毛片视频免费看| 希望影院高清免费观看视频| 久久久久亚洲AV成人网| 国产午夜亚洲精品| 精品免费国产一区二区| 亚洲色图在线观看| 青青青视频免费观看| 毛片免费在线观看网址| 亚洲精品乱码久久久久久按摩 | 亚洲精品在线免费观看视频| 99免费在线观看视频| 亚洲国产日韩成人综合天堂 | 亚洲国产一区在线| 亚洲一区免费在线观看| 亚洲日本一区二区三区在线| 国产大陆亚洲精品国产| 最新免费jlzzjlzz在线播放| 亚洲乱码国产乱码精华| 亚洲国产精品人人做人人爽 | 久久精品国产亚洲av麻豆图片| 97在线免费观看视频| 国产一区二区免费在线| 亚洲色大情网站www| 免费能直接在线观看黄的视频| 亚洲乱码卡一卡二卡三| 美女视频黄的全免费视频网站| 一本色道久久综合亚洲精品蜜桃冫| 日韩a级毛片免费视频| 亚洲男同gay片| 亚洲AV网站在线观看| a级毛片毛片免费观看久潮| 久久综合亚洲色HEZYO社区| 最好看最新的中文字幕免费| 国产成人精品日本亚洲网站| 成全视成人免费观看在线看| 亚洲精品高清国产麻豆专区| 国产精品酒店视频免费看|