java學(xué)習(xí)

          java學(xué)習(xí)

           

          java中文件的處理1

          一,復(fù)制文件
                  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);
          /*如果你想讓文件的復(fù)制加快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) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 谷城县| 鱼台县| 兴安盟| 卢氏县| 招远市| 屯留县| 应城市| 随州市| 天津市| 大厂| 桓台县| 神农架林区| 平度市| 都匀市| 盐边县| 隆子县| 松潘县| 万州区| 蓝山县| 大丰市| 宣城市| 武邑县| 迭部县| 昆明市| 桦川县| 汶川县| 长兴县| 湄潭县| 阳曲县| 无棣县| 漾濞| 武义县| 沅陵县| 夏河县| 尼勒克县| 闸北区| 英山县| 绥阳县| 拉孜县| 蓬溪县| 榆林市|