⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileopener.java

📁 1.文件和目录管理
💻 JAVA
字号:
/** * Class FileOpener is a class open files. * Once used an instance of the class to open a file, * you can get the elementary information of the file, * and if the file is a foder,you could get the file list of it. *  * @author  lcw */package file;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;import java.io.IOException;import java.text.*;import java.util.*;public class FileOpener {        private File f;	private StringBuffer info;    private String[] fileList;        public FileOpener() {    	    	info = new StringBuffer();    }    /**     * method to open file,it may be throws FileNameEmptyException     * @param fileName is suppose to be the name of the file to open     * @return a file build on the file name     */       public File openFile(String fileName) throws FileNameEmptyException{                if(fileName.length() == 0)         	throw new FileNameEmptyException();                else return new File(fileName);            }        /**     * method to get the information of a file to be open     * @param fileName is suppose to be the name of the file to open     * @return the information as StringBuffer     */    public StringBuffer getInfo(String fileName) {    	    	try {    		DateFormat formatter = DateFormat.getInstance();    		f = openFile(fileName);    		info.delete(0,info.length());    		info.append("File :    " + f.getAbsolutePath() + "\n");    		if(f.exists()){    				info.append("exists: true" + "\n");				info.append("path: " + f.getPath() + "\n");				info.append("canRead: " + f.canRead() + "\n");    				info.append("canWrite: " + f.canWrite() + "\n");				info.append("isHidden: " + f.isHidden() + "\n");				info.append("lastModified: " + formatter.format(new Date(f.lastModified()))    					 + "\n");    			if(f.isFile()) {    			  				    				info.append("isFile: " + "true \n");    				info.append("long: " + f.length() + "\n");    			}    			else {    				    				info.append("isDirectory: true \n");    				fileList = f.list();		    			}    		}else {    			    			info.append("exists: fasle" + "\n");    		}    		    	} catch(FileNameEmptyException e) {    	}finally {    		return info;    	}    	    }        /**     * method to get the subfiles of a file     * @return the sub files as if the file is directory.     */    public String[] getFileList() {   	    	if(f.isFile())    		return new String[]{"No Files","It's a file"};    	else return fileList;    }    	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -