<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 閱讀(244) 評論(0)  編輯  收藏

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


    網站導航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     
    主站蜘蛛池模板: 亚洲天堂在线播放| 国产亚洲日韩在线三区| 亚洲成人免费网站| 67pao强力打造高清免费| 亚洲AV日韩AV永久无码绿巨人 | 久久久久亚洲av无码专区| 精品亚洲永久免费精品| 国产AV无码专区亚洲AV毛网站 | 亚洲国产成a人v在线| 国产电影午夜成年免费视频 | 亚洲资源在线视频| 亚洲人成免费网站| 最新亚洲精品国偷自产在线| 成年女人色毛片免费看| 亚洲avav天堂av在线网毛片| 亚洲精品偷拍视频免费观看| 91免费福利视频| 久久亚洲日韩看片无码| 亚洲第一成年免费网站| 亚洲av无码专区首页| 国产成人精品亚洲精品| 久久久久久久岛国免费播放 | 亚洲成人免费网站| 国产精品99久久免费| fc2成年免费共享视频18| 亚洲AV日韩AV天堂一区二区三区| 91老湿机福利免费体验| 亚洲AV无码一区二区三区牲色| 国产91精品一区二区麻豆亚洲| 9420免费高清在线视频| 亚洲av无码有乱码在线观看| 亚洲日韩精品一区二区三区| 18pao国产成视频永久免费| 久久亚洲精品无码gv| 亚洲精品无码永久在线观看你懂的 | 亚洲综合网站色欲色欲| 免费在线观看h片| 色吊丝性永久免费看码| 亚洲综合免费视频| 天堂亚洲免费视频| 亚洲成人免费网址|