隨筆-204  評論-90  文章-8  trackbacks-0
          1.使用FileInputStream和FileOutputStream,代碼如下:sFlieName和tFileName分別為源文件(帶路徑)和目標文件(帶路徑)
          try?{
          ????
          //?Save?as?File
          ????FileInputStream?input?=?new?FileInputStream(new?File(
          ????????????sFileName));
          ????FileOutputStream?output?
          =?new?FileOutputStream(
          ????????????
          new?File(tFileName));
          ????
          int?b;
          ????
          while?(true)?{
          ????????
          if?(input.available()?<?1024)?{
          ????????????
          while?((b?=?input.read())?!=?-1)?{
          ????????????????output.write(b);
          ????????????}

          ????????????
          break;
          ????????}
          ?else?{
          ????????????input.read(buffer);
          ????????????output.write(buffer);
          ????????}

          ????}

          ????input.close();
          ????output.close();
          ????
          continue;
          }
          ?catch?(FileNotFoundException?e)?{
          ????e.printStackTrace();
          }
          ?catch?(IOException?e)?{
          ????e.printStackTrace();
          }
          2.使用FileChennal,本人認為這種方法在文件移動,不做別的處理時很好用,又好看,哈哈,特別是它的transferTo(),很棒啊,想了解看文檔啊,sFileName和tFileName同上
          try?{
          ????
          //?Save?as?File
          ????FileInputStream?input?=?new?FileInputStream(sFileName);????????????????????
          ????FileOutputStream?output?
          =?new?FileOutputStream(tFileName);
          ????FileChannel?infileChannel?
          =?input.getChannel();???
          ????FileChannel?outfileChannel?
          =?output.getChannel();???
          ????
          long?size?=?infileChannel.size();???
          ????infileChannel.transferTo(
          0,?size,?(WritableByteChannel)outfileChannel);????
          ????
          continue;
          }
          ?catch?(FileNotFoundException?e)?{
          ????e.printStackTrace();
          }
          ?catch?(IOException?e)?{
          ????e.printStackTrace();
          }

          posted on 2006-07-05 16:21 一凡 閱讀(5144) 評論(0)  編輯  收藏 所屬分類: JAVA 基礎
          <2006年7月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(9)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          學習資源

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 新源县| 铁岭市| 隆安县| 荥经县| 阿荣旗| 鄂州市| 奈曼旗| 恩平市| 肇源县| 商南县| 耿马| 黑河市| 安仁县| 申扎县| 柞水县| 东乡| 白城市| 海林市| 安国市| 健康| 博乐市| 萝北县| 鹿泉市| 禄丰县| 凤阳县| 中卫市| 南投市| 三台县| 邢台市| 工布江达县| 龙陵县| 铁岭市| 漳州市| 丹凤县| 东宁县| 固始县| 林芝县| 新化县| 弥勒县| 元谋县| 阆中市|