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

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

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();

        } 
    }
}

 

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 午夜国产福利视频一区 | 青青青青久久国产片免费精品 | 久久青青草视频在线观 | 免费全看男女拍拍拍的视频 | 三级黄色图片 | 爽好舒服宝贝添奶吻戏 | 国产视频a区 | 久久人妻无码毛片A片麻豆 久久热这里只有 精品 | 亚洲国内精品 | 91亚洲精品第一综合不卡播放 | 国产偷窥女洗浴在线观看亚洲 | 久久免费看少妇高潮A片特爽 | 香蕉成人999视频 | 精品无码国产AV一区二区三区 | 午夜办公室在线观看高清电影 | 亚洲国产精品高清在线 | 日韩免费在线视频观看 | 亚洲 欧美 国产 日韩 字幕 | 国产精品九九免费视频 | 深夜在线影院 | 国产欧美日韩综合二区三区 | 亚洲国产精品ⅴa在线观看 亚洲国产高清一区二区三区 | 火影忍者小南裸羞羞漫画 | ady成人映画网站官网 | gay台湾无套男同志可播放 | 免费精品99久久国产综合精品 | 激情小视频网站 | 色依依视频视频在线观看 | 欧美日韩国产一区二区三区伦 | 美女被爆操 | 古装床戏做爰无遮挡三级 | 男老头澡堂gay老头456 | 色综合久久最新中文字幕 | 精品欧美男同同性videos | 半挠脚心半黄的网站 | 国产思妍小仙女一二区 | 青草碰人人澡人人澡 | 美女自插| 国产成人小视频在线观看 | 欧美特级午夜一区二区三区 | 四虎在线播放 |