java學習

          java學習

           

          java中文件的處理1

          一,復制文件
                  File oldFile = new File("F:/FavoriteVideo/0CAMGLN0K.jpg");
          File newFile = new File("F:/FavoriteVideo/yang.jpg");
          if(!oldFile.exists()){
          newFile.createNewFile();
          }
          FileInputStream input = new FileInputStream(oldFile);
          /*如果你想讓文件的復制加快BufferedInputStream bufferedInput = new BufferedInputStream(input);*/
          FileOutputStream output = new FileOutputStream(newFile );
          /*BufferedOutputStream bufferedOut = new BufferedOutputStream(output);*/
          byte[]  buffer = new byte[512];
          int b = 0;
          long startTime = System.currentTimeMillis();
          while(b!=-1){
          b=input.read(buffer);
          output.write(buffer, 0, buffer.length);
          }
          long endTime = System.currentTimeMillis();
          System.out.println(endTime-startTime);
          input.close();
          output.flush();
          output.close();
          二文件的查詢方法
          public class ShowFilePath {
          public void show(String path){
          File f = new File(path);
          if(f.isFile()){
          System.out.println(f.getPath());
          }else if(f.isDirectory()){
          File[] files = f.listFiles();
          if(files!=null){
          for(File file:files ){
          if(file.isFile()){
          System.out.println(file.getPath());
          }else {
          System.out.println("["+file.getPath()+"]");
          show(file.getPath());
          }
          }
          }
          }






          posted on 2011-11-18 13:13 楊軍威 閱讀(177) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 法库县| 大姚县| 天柱县| 白沙| 屯昌县| 游戏| 广东省| 克拉玛依市| 商水县| 三台县| 潮安县| 昭通市| 尼玛县| 罗平县| 百色市| 海丰县| 远安县| 本溪市| 科技| 谷城县| 阜宁县| 兴和县| 疏附县| 孟州市| 墨玉县| 大竹县| 商都县| 民权县| 白沙| 颍上县| 息烽县| 乌审旗| 信阳市| 普安县| 和田市| 司法| 临漳县| 介休市| 温州市| 牡丹江市| 安远县|