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

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲三级中文字幕| 亚洲欧洲视频在线观看| 最新亚洲人成网站在线观看| 99蜜桃在线观看免费视频网站| 亚洲精品第一国产综合精品99| 国产亚洲美女精品久久久久| 国产男女猛烈无遮挡免费视频| 亚洲乱色伦图片区小说| 一区二区3区免费视频| 免费国产人做人视频在线观看| 国产精品亚洲专区无码唯爱网| 日本最新免费不卡二区在线| 国产精品亚洲专区在线播放| 全亚洲最新黄色特级网站 | 日韩电影免费在线观看| 亚洲AV区无码字幕中文色 | 国产免费区在线观看十分钟| 久99精品视频在线观看婷亚洲片国产一区一级在线 | 中文字幕免费在线视频| 亚洲日韩国产精品第一页一区| 大地资源在线资源免费观看| 久久久久亚洲av无码专区导航 | 亚洲最大福利视频| 免费a级黄色毛片| 中国一级毛片视频免费看| 亚洲人成在线影院| www.黄色免费网站| 亚洲免费观看视频| 亚洲一区二区三区免费观看| 亚洲熟妇av午夜无码不卡| 免费国产成人午夜电影| 成在人线av无码免费高潮喷水| 亚洲男女一区二区三区| 午夜一级毛片免费视频| 中文字幕无码免费久久9一区9| 亚洲狠狠久久综合一区77777| 黄页网站免费在线观看| 一级特级aaaa毛片免费观看| 亚洲网站视频在线观看| 一级毛片在线播放免费| 亚洲色图.com|