createurl.java

来自「ORACLE AQ sample 演示的如何出列」· Java 代码 · 共 67 行

JAVA
67
字号
package oracle.otnsamples.AQ.Helper;

/**
 * @author  Rajat Gupta
 * @version 1.0
 *
 * Name of the Application        :  CreateURL.java
 * Development Environment        :  Oracle 9i JDeveloper
 * Creation/Modification History  :
 *
 *    Rajat Gupta       15-Jan-2001      Created
 *
 */

// Net Imports
import java.net.URL;
import java.net.MalformedURLException;

// IO Imports
import java.io.File;

/**
 * This class is used for Creating the URL to a particular file. The file name
 * and its path is passed to the method and which creates a URL to it and
 * returns it.
 */
public class CreateURL{
  /**
   * Empty Constructor
   */
  public CreateURL(){
  }

  /**
   * This method creates the URL to the specified file.
   *
   * @param p_fileName Fully qualified name and path to the file
   * @exception Exception Thrown in case the file is not found
   * @return URL Object to the file
   */
  public URL getURL(String p_fileName) throws Exception{
    URL url = null;
    try{
       url = new URL(p_fileName);
    }catch (MalformedURLException ex){
       File f = new File(p_fileName);
       try{
         String path = f.getAbsolutePath();
         String fs = System.getProperty("file.separator");
         if (fs.length() == 1){
           char sep = fs.charAt(0);
           if (sep != '/')
             path = path.replace(sep, '/');
           if (path.charAt(0) != '/')
             path = '/' + path;
         }
         path = "file://" + path;
         url = new URL(path);
       }catch (MalformedURLException e){
          e.printStackTrace();
          throw new Exception("AQ-1006");
       }
    }
   return url;
  }
}

⌨️ 快捷键说明

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