使用java.util.Properties工具制作自定义访问配置文件信息
import ch.qos.logback.classic.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStreamReader; import java.util.Properties; /** * Created by Administrator on 2019/3/25. */ public class propertiesutil { public final static Logger logger= (Logger) LoggerFactory.getLogger(propertiesutil.class); public static Properties properties; static { String filename="ftp.properties"; properties=new Properties(); try { properties.load(new InputStreamReader(propertiesutil.class.getClassLoader().getResourceAsStream(filename))); } catch (IOException e) { e.printStackTrace(); logger.error("配置文件读取失败",e); } } public static String getValue(String key){ String val=properties.getProperty(key.trim()); if(val==null){ return null; }else{ return val.trim(); } } public static String getValue(String key,String defval){ String val=properties.getProperty(key.trim()); if(val==null){ return defval; }else{ return val.trim(); } } }