一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - java生成文件夾和文件的簡單示例分享

java生成文件夾和文件的簡單示例分享

2019-11-17 14:16java技術網 JAVA教程

這篇文章主要介紹了java生成文件夾和文件的簡單示例,需要的朋友可以參考下

實現文件夾和文件生成

 

復制代碼代碼如下:

package com.gotobus.common;

 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class JFile {

 public static boolean createFile(String destFileName) {  
        File file = new File(destFileName);  
        if(file.exists()) {  
         return false;  
        }  
        if (destFileName.endsWith(File.separator)) {  
         return false;  
        }  
        if(!file.getParentFile().exists()) {  
      if(!file.getParentFile().mkdirs()) {  
       return false;  
            }  
        }  
        try {  
            if (file.createNewFile()) {  
             return true;  
            } else {  
             return false;  
            }  
        } catch (IOException e) {  
            e.printStackTrace();  
            return false;  
        }  
    }  

     public static boolean createDir(String destDirName) {  
        File dir = new File(destDirName);  
        if (dir.exists()) {  
         return false;  
        }  
        if (!destDirName.endsWith(File.separator)) {  
            destDirName = destDirName + File.separator;  
        }  
       if (dir.mkdirs()) {  
           return true;  
        } else {  
            return false;  
        }  
    }  

    public static String createTempFile(String prefix, String suffix, String dirName) {  
        File tempFile = null;  
        if (dirName == null) {  
            try{  
                tempFile = File.createTempFile(prefix, suffix);  
                return tempFile.getCanonicalPath();  
            } catch (IOException e) {  
                e.printStackTrace();  
               return null;  
            }  
        } else {  
            File dir = new File(dirName);  
            if (!dir.exists()) {  
                if (!JFile.createDir(dirName)) {  

                    return null;  
                }  
            }  
            try {  
                tempFile = File.createTempFile(prefix, suffix, dir);  
                return tempFile.getCanonicalPath();  
            } catch (IOException e) {  
                e.printStackTrace();  
                return null;  
            }  
        }  
    }

    public static void copyFile(String oldPath, String newPath) { 
        try { 
            int bytesum = 0; 
            int byteread = 0; 
            File oldfile = new File(oldPath); 
            if (oldfile.exists()) { 
             InputStream inStream = new FileInputStream(oldPath); 
                FileOutputStream fs = new FileOutputStream(newPath); 
                byte[] buffer = new byte[1444]; 
                int length; 
                while ( (byteread = inStream.read(buffer)) != -1) { 
                    bytesum += byteread; 
                    fs.write(buffer, 0, byteread); 
                } 
                inStream.close(); 
            } 
        } 
        catch (Exception e) { 
                e.printStackTrace();

        } 
    }
}

 

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 成人在线免费看 | 91热国内精品永久免费观看 | 满城尽带黄金甲大胸片 | 2022色婷婷综合久久久 | 欧美国产在线视频 | 性导航h | 国产区成人综合色在线 | 国产剧情一区 | 欧美艳星julnaann | 无码乱人伦一区二区亚洲一 | 美女私人影院 | 帅小伙和警官同性3p | 911精品国产亚洲日本美国韩国 | 欧美深夜在线 | 亚洲精品福利你懂 | 久久综合久综合久久鬼色 | 久久热国产在线视频 | 大象传媒短视频网站 | 1377大但人文艺术包子铺 | 无限韩国视频免费播放 | 日本一区二区三区久久精品 | 日本三级在丈面前被耍了 | 性伴交换多p | 色综合97天天综合网 | 日本嫩小xxxxhd | 日韩天堂视频 | 免费看一区二区三区 | 国产亚洲精品福利在线 | 暴露狂婷婷 | 高h舔穴 | 国产色视频一区二区三区 | 欧洲网色偷偷亚洲男人的天堂 | 日本加勒比在线播放 | 黑帮少爷爱上我第8集在线观看 | 2021国产麻豆剧传媒剧情最新 | 国产日韩免费视频 | 高h生子双性美人受 | 6080欧美一区二区三区四区 | 久久九九久精品国产尤物 | 无人区乱码区1卡2卡三卡在线 | 大好硬好深好爽想要视频 |