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

📄 tempfilemanager.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
字号:
/*** $Id: TempFileManager.java,v 1.3 2001/05/07 12:37:22 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may redistribute it and/or modify it under the terms of the GNU** General Public License as published by the Free Software Foundation.** Version 2 of the license should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail;import java.io.File;import java.util.Vector;/** * A class to manage temporary files by name, * allowing temporary file names to be produced in a sequenced fasion, * as well as the deletion of all temporary files created. */public class TempFileManager{  private String    prefix_ = null;  private String    suffix_ = null;  private String    directory_ = null;  private int       lastId_ = 0;  private Vector    fileNames_ = new Vector();  /**   * Create a temporary file manager which will produce file names with   * using the given prefix and suffix.   * <p>   * File names have the following structure: [prefix]##[suffix] where the   * ## is the id of the file name.   * <p>   * The directory must be set before using the temporary file manager by   * calling setDirectory() below.   */  public  TempFileManager( String prefix, String suffix ) {    prefix_ = prefix;    suffix_ = suffix;  }// accessors  /**   * Get the prefix used when constructing file names.   *   * @return the prefix used when constructing file names   */  public String  getPrefix() {    return prefix_;  }  /**   * Get the suffix used when constructing file names.   *   * @return the suffix used when constructing file names   */  public String  getSuffix() {    return suffix_;  }  /**   * Get the current directory used when creating temporary files.   *   * @return the current directory used when creating temporary files.   */  public String  getDirectory() {    return directory_;  }  /**   * Get the number of temporary file names constructed, which may or   * may not be the number of actual temporary files created.   *   * @return the number of temporary file names constructed   */  public int  getNumberOfFiles() {    return fileNames_.size();  }// mutators  /**   * Set the directory to be used when creating temporary files.   *   * @param directory the directory to be used when creating temporary files   */  public void  setDirectory( String directory ) {    directory_ = directory;  }// helpers  /**   * Get a temporary file name.   * The file name is created from the manager's prefix and given suffix.   * If the given suffix is null then the manager's suffix is used.   *   * @param suffix the given suffix of the file name or null   */  public String  getFilename( String suffix ) {  // use the default suffix if necessary    if ( suffix == null ) {      suffix = suffix_;    }  // create a temporary file name    String xfilename = directory_ + File.separator + prefix_ + "-" + lastId_ + suffix;    lastId_++;    fileNames_.addElement( xfilename );    return xfilename;  }  /**   * Delete all temporary files by name.   * The list of names maintained by the manager is used to delete any   * temporary files created.   */  public void  deleteAllFiles() {    int count = 0;    int numFiles = fileNames_.size();    for ( int idx = 0 ; idx < numFiles ; idx++ ) {      String fileName = (String)fileNames_.elementAt( idx );      File f = new File( fileName );      if ( f.exists() && f.isFile() ) {        f.delete();        count++;      }    }    System.err.println( "Deleted " + count + " temporary documents." );  }  /**   * Returns a string representation of the object.   * <p>   * Implements Object.toString()   *   * @return a string representation of the object   */  public String  toString() {    return "TempFileManager: p-" + prefix_ + ", s-" + suffix_ + ", d-" + directory_;  }}

⌨️ 快捷键说明

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