<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    巷尾的酒吧

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      64 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks
    package com.abin.test.result;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    //以前做Java很少會用到文件,原因之一是我做的項目的那一塊很少用到文件操作,只用過文件上傳,應我同學的要求,今天幫他實現了一下,放在這里

    //以備以后再用的著的話好找,這些都是參考網上好多人的心血而成的。
    public class CopyFile1 {
    //復制文件并且改名:
        
    public static void doCopyFile(String fromPath ,String toPath) throws IOException{
            String toNewPath
    =toPath+fromPath.subSequence(fromPath.lastIndexOf("\\")+1, fromPath.length());
            File srcFile 
    = new File(fromPath);
            File destFile 
    = new File(toNewPath);
            FileInputStream input 
    = new FileInputStream(srcFile);
            
    try {
                FileOutputStream output 
    = new FileOutputStream(destFile);
                
    try {
                    
    byte[] buffer = new byte[4096];
                    
    int n = 0;
                    
    while (-1 != (n = input.read(buffer))) {
                        output.write(buffer, 
    0, n);
                    }
                } 
    finally {
                    
    try {
                        
    if (output != null) {
                            output.close();
                        }
                    } 
    catch (IOException ioe) {
                        
    // ignore
                    }
                }
            } 
    finally {
                
    try {
                    
    if (input != null) {
                        input.close();
                    }
                } 
    catch (IOException ioe) {
                    
    // ignore
                }
            }
        }
    //移動文件并且改名:
        
    public static void doCopyFileAndUpdateFileName(String fromPath ,String toPath,String newName) throws 

    IOException{
            String toNewPath
    =toPath+newName;
            File srcFile 
    = new File(fromPath);
            File destFile 
    = new File(toNewPath);
            FileInputStream input 
    = new FileInputStream(srcFile);
            
    try {
                FileOutputStream output 
    = new FileOutputStream(destFile);
                
    try {
                    
    byte[] buffer = new byte[4096];
                    
    int n = 0;
                    
    while (-1 != (n = input.read(buffer))) {
                        output.write(buffer, 
    0, n);
                    }
                } 
    finally {
                    
    try {
                        
    if (output != null) {
                            output.close();
                        }
                    } 
    catch (IOException ioe) {
                        
    // ignore
                    }
                }
            } 
    finally {
                
    try {
                    
    if (input != null) {
                        input.close();
                    }
                } 
    catch (IOException ioe) {
                    
    // ignore
                }
            }
        }
    //刪除文件:
        
    public static void doDeleteFile(String path) throws IOException{
            File file
    =new File(path);
            
    if(file.exists()||file.isFile()||!file.isDirectory()){
                file.delete();
                file.deleteOnExit();
            }
        }
    //修改文件名:
        
    public static void doUpdateFileName(String path1,String newName1) throws IOException{
            String path
    =path1.substring(0, path1.lastIndexOf("\\"))+"\\";
            System.out.println(path);
            File newFile
    =new File(path+newName1);
            File file
    =new File(path1);
            file.renameTo(newFile);
               
        }
        
    public static void main(String args[])throws Exception {
            String fromPath
    ="e:\\love.jpg";
            String toPath
    ="e:\\demo\\";
            String newName
    ="abin.jpg";
            String newName1
    ="abin.jpg";
            String path
    ="e:\\demo\\love.jpg";
            String path1
    ="e:\\demo\\love.jpg";
        
    //    new CopyFile1().doCopyFile(fromPath, toPath);
        
    //    new CopyFile1().doCopyFileAndUpdateFileName(fromPath, toPath, newName);
        
    //    new CopyFile1().doDeleteFile(path);
            new CopyFile1().doUpdateFileName(path1, newName1);
            
            CopyFile1 aaa
    =new CopyFile1();
            aaa.doCopyFile(fromPath, toPath);
            
            
        }

    }
    posted on 2011-09-28 23:24 abing 閱讀(239) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲在成人网在线看| 在线观看免费精品国产| 国产三级免费电影| 久久免费高清视频| 香蕉国产在线观看免费| 亚洲精品中文字幕无乱码| 日韩亚洲精品福利| 69av免费视频| 一区二区三区在线观看免费| 亚洲视频在线视频| 五月天网站亚洲小说| 亚洲日韩国产一区二区三区| 成在人线AV无码免费| 99re视频精品全部免费| 三上悠亚电影全集免费| 福利免费在线观看| av成人免费电影| 国产免费AV片在线观看播放| 亚洲精品无码专区在线| 亚洲欧洲日韩极速播放| 亚洲H在线播放在线观看H| 亚洲日本香蕉视频| 亚洲三级在线免费观看| 亚洲AV无码一区二区三区牛牛| 亚洲另类春色校园小说| 中文字幕亚洲综合小综合在线| 亚洲国产精品日韩在线观看 | 亚洲大尺度无码专区尤物| 国产AV无码专区亚洲AWWW| 亚洲人成人网站色www| 亚洲韩国—中文字幕| 亚洲三级电影网址| 亚洲免费福利在线视频| 亚洲av综合日韩| a拍拍男女免费看全片| a毛片基地免费全部视频| 免费人成网站在线播放| 国产∨亚洲V天堂无码久久久| 亚洲AV无码专区在线播放中文| 两个人看www免费视频| 日韩免费在线视频|