论坛首页 入门技术论坛

动态数组的增长

浏览 1388 次
该帖已经被评为新手帖
作者 正文
   发表时间:2011-06-01  

   

       // 取得のファイル内容の初期化
        byte[] result = new byte[DocumentConstants.FILE_CONTENTENT_SIZE];
  try {
     // InputStreamから、結果のバイト配列に保存する
           int length = 0;
           int count = 0;
           byte[] bytes = new byte[DBConstants.INIT_STRING_BUFFER_COUNT];
           while ((length = inputStream.read(bytes)) != -1) {
            if (count + length > result.length) {
              byte[] resultBuffer = new byte[result.length + DocumentConstants.FILE_CONTENTENT_SIZE];
           System.arraycopy(result, 0, resultBuffer, 0, result.length);
           result = resultBuffer;
            }
              System.arraycopy(bytes, 0, result, count, length);
              count = count + length;
           }
           // ファイル内容長さを設定
           fileContentSize[0] = count;

 

其实也就是模仿vector类中的方法实现。

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics