国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

安卓 文件相關

2019-11-06 09:41:22
字體:
來源:轉載
供稿:網(wǎng)友
	//文件不存在就創(chuàng)建	public static File makeRootDirectory(String filePath) {		File file = null;		try {			file = new File(filePath);			if (!file.exists()) {				file.mkdir();			}		} catch (Exception e) {			LogUtils.i(Tag, e+"");		}		return file;	}	/**	 * 生成文件	 * */ 	public static File makeFilePath(String filePath, String fileName) {		File file = null;		makeRootDirectory(filePath);		try {			file = new File(filePath + fileName);			if (!file.exists()) {				file.createNewFile();			}		} catch (Exception e) {			e.PRintStackTrace();		}		return file;	}	/**	 * 寫入文件	 * */	public static void writeFile(String fileName, String message){		message = message+" ";		LogUtils.i(Tag, "message:"+message);		if (fileIsExists(fileName)) {			try {				FileOutputStream fileOutputStream = new FileOutputStream(fileName);				byte [] bytes = message.getBytes();				fileOutputStream.write(bytes);				fileOutputStream.flush();				LogUtils.i(Tag, "message:"+message);				fileOutputStream.close();			} catch (FileNotFoundException e) {				// TODO Auto-generated catch block				e.printStackTrace();			} catch (IOException e) {				// TODO Auto-generated catch block				e.printStackTrace();			}		}	}		/**	 * 讀文件	 * */	private String readFile(String fileName) throws IOException {        String res = "";        try {                        FileInputStream fin = new FileInputStream(fileName);            int length = fin.available();                        byte[] buffer = new byte[length];            fin.read(buffer);                        res = EncodingUtils.getString(buffer, "UTF-8");                        fin.close();                    } catch (Exception e) {            e.printStackTrace();        }        return res;    }	/**	 * 文件是否存在	 * */	public static boolean fileIsExists(String filePath){		try{			File f=new File(filePath);			if(!f.exists()){				return false;			}		}catch (Exception e) {			// TODO: handle exception			return false;		}		return true;	}	/**	 * 刪除文件夾及子目錄	 * */	public static Boolean deleteFile(File file){		if(file.isDirectory()){			File[] files = file.listFiles();			for(int i=0; i<files.length; i++){				deleteFile(files[i]);			}		}		return file.delete();	}	/**	 * 判斷文件是否為空	 * */	public static  boolean deleteEmptyDirectory(File path) {   		if( path.exists() ) {  //判斷是否為空 			File[] files = path.listFiles();   			for(int i=0; i<files.length; i++) {//如果不為空不刪除   				if(files[i].isDirectory()) {   					deleteEmptyDirectory(files[i]);   				}   				else {//執(zhí)行刪除   					files[i].delete();   				}   			}   		}   		return( path.delete() );   	}   	//獲取文件里面的圖片列表	public static List<Photos> getListOfPictures(File fileName){		LogUtils.i(Tag, "fileName:   "+fileName);		File[] files = fileName.listFiles();//		LogUtils.i(Tag, "files fileName.listFiles() "+fileName.listFiles());		List<Photos> listPhoto = new ArrayList<Photos>();		if (files != null) {			for (int i = 0; i < files.length; i++) {				File file = files[i];  				if (file.getName().substring(file.getName().lastIndexOf(".")+1).equals("png")) {					LogUtils.i(Tag, "file.getName() "+file.getName());					Photos photos = new Photos();					photos.setPhotoName(file.getName());					listPhoto.add(photos);				}				}		}		return listPhoto;	}	/**	 * 獲取文件夾下所有指定文件	 * */	public static void getAllFile(File root){		File files[] = root.listFiles();		if (files != null) {			for (File f: files) {				if (f.isDirectory()) {					getAllFile(f);				}else {					LogUtils.i(Tag, "f: "+f);					LogUtils.i(Tag, "lastModified: "+f.lastModified()/1000);				}			}		}	}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 灵石县| 黄山市| 双江| 阿鲁科尔沁旗| 高淳县| 横峰县| 安顺市| 江城| 庆元县| 东阳市| 平谷区| 岳阳市| 宿迁市| 喀喇沁旗| 石门县| 黔西县| 凤山县| 鹤峰县| 安西县| 崇左市| 巩留县| 琼中| 咸阳市| 林西县| 株洲县| 重庆市| 静乐县| 临猗县| 馆陶县| 洪湖市| 浦江县| 新营市| 乐东| 尉氏县| 仙居县| 杭锦旗| 蓝山县| 蓝山县| 金堂县| 临泽县| 衡阳市|