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 楊軍威 閱讀(176) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 金湖县| 怀安县| 西安市| 洮南市| 新绛县| 彭水| 饶河县| 南川市| 柞水县| 遵化市| 寿宁县| 洛宁县| 德昌县| 盐源县| 吐鲁番市| 伊通| 赤峰市| 黄骅市| 松原市| 北宁市| 朔州市| 娱乐| 靖州| 余庆县| 铜山县| 开江县| 夏津县| 全南县| 承德市| 明溪县| 轮台县| 衡南县| 南华县| 襄汾县| 邛崃市| 华蓥市| 富顺县| 囊谦县| 涞源县| 兴和县| 苏尼特右旗|