📄 fileopener.java
字号:
/** * This file is part of the jcrontab package * Copyright (C) 2001-2003 Israel Olalla * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307, USA * * For questions, suggestions: * * iolalla@yahoo.com * */package org.jcrontab.data; import java.io.InputStream;import java.io.FileInputStream;import java.io.File;import java.io.IOException;import java.util.Properties;/** * This class get an InputStream using the right method, File or * getResourceAsStream, The idea of this way of openning files is from * Sergey Udalstov * @author $Author: iolalla $ * @version $Revision: 1.4 $ */public class FileOpener { private static String type; static { type = org.jcrontab.Crontab.getInstance().getProperty("org.jcrontab.data.FileOpener"); } /** * This method is the reason of this class and basically loads the * File with the given method. * @return InputStream The inputStream to work with * @param Class cl The class to load from only used if getResourceAsStream * is used * @param name String the name of the file to load * @param type how to load the file. * @throws Exception the thrown exceptions */ public InputStream getInputStream(Class cl, String name) throws Exception { InputStream is = null; if ("class".compareToIgnoreCase(type) == 0) { is = cl.getClassLoader().getResourceAsStream(name); if (is == null) throw new IOException(name + " not Found."); } else if ("file".compareToIgnoreCase(type) == 0) { File file = new File (name); is = new FileInputStream(file); } else { throw new UnsupportedOperationException("should call with class or file" + " no with : " + type ); } return is; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -