- 浏览: 231422 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (127)
- 求职技巧 (1)
- java语言 (27)
- 数据库 (1)
- JDK 6.0学习笔记 (5)
- TOMCAT (2)
- JSP&Servlet (3)
- Data Binding (1)
- Windows (1)
- DB2 (15)
- Hibernate (5)
- XML (1)
- Financial Business (1)
- 项目管理 (0)
- Open source Framework (1)
- 总结思考反思 (2)
- Oracle (1)
- English Study (2)
- Other (28)
- java 模式 (8)
- en study (2)
- 异常处理 (4)
- Java 基础知识 (3)
- JDK1.5 Tiger (2)
- SSO (1)
- 开发中遇到的问题解决 (1)
最新评论
-
sonull:
怒赞!困扰多年的问题,就因为这个问题我一直都用subversi ...
如何使eclipse中subclipse插件的显示语言设置为英文 -
hanmiao:
果真如此,很好用,重启 eclipse 之后 svnclips ...
如何使eclipse中subclipse插件的显示语言设置为英文 -
wystark:
...
如何使eclipse中subclipse插件的显示语言设置为英文 -
minn84:
...
对年轻人的几点忠告 -
leizisdu:
引用 if(不包含物品i仅是可能的)感觉有些拗口
0/1背包问题-递归、动态规划
Key Word: properties 文件.
使用J2SE API读取Properties文件的六种方法
1。使用java.util.Properties类的load()方法
示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name));
Properties p = new Properties();
p.load(in);
2。使用java.util.ResourceBundle类的getBundle()方法
示例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());
3。使用java.util.PropertyResourceBundle类的构造函数
示例: InputStream in = new BufferedInputStream(new FileInputStream(name));
ResourceBundle rb = new PropertyResourceBundle(in);
4。使用class变量的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getResourceAsStream(name);
Properties p = new Properties();
p.load(in);
5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);
Properties p = new Properties();
p.load(in);
6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法
示例: InputStream in = ClassLoader.getSystemResourceAsStream(name);
Properties p = new Properties();
p.load(in);
补充
Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法
示例:InputStream in = context.getResourceAsStream(path);
Properties p = new Properties();
p.load(in);
完整的示例,可以参考附件文件
如何上传文件,谁知道请告诉以下。 只好把source都贴上来了
JProperties.java文件
/**
** 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 com.kindani;
//import javax.servlet.ServletContext;
import java.util.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
/**
* 使用J2SE API?取Properties文件的六?方法
* User: SYNFORM
* Date: 2005/07/12
* Time: 18:40:55
* To change this template use File | Settings | File Templates.
*/
public class JProperties {
public final static int BY_PROPERTIES = 1;
public final static int BY_RESOURCEBUNDLE = 2;
public final static int BY_PROPERTYRESOURCEBUNDLE = 3;
public final static int BY_CLASS = 4;
public final static int BY_CLASSLOADER = 5;
public final static int BY_SYSTEM_CLASSLOADER = 6;
public final static Properties loadProperties(final String name, final int type) throws IOException {
Properties p = new Properties();
InputStream in = null;
if (type == BY_PROPERTIES) {
in = new BufferedInputStream(new FileInputStream(name));
assert (in != null);
p.load(in);
} else if (type == BY_RESOURCEBUNDLE) {
ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());
assert (rb != null);
p = new ResourceBundleAdapter(rb);
} else if (type == BY_PROPERTYRESOURCEBUNDLE) {
in = new BufferedInputStream(new FileInputStream(name));
assert (in != null);
ResourceBundle rb = new PropertyResourceBundle(in);
p = new ResourceBundleAdapter(rb);
} else if (type == BY_CLASS) {
assert (JProperties.class.equals(new JProperties().getClass()));
in = JProperties.class.getResourceAsStream(name);
assert (in != null);
p.load(in);
// return new JProperties().getClass().getResourceAsStream(name);
} else if (type == BY_CLASSLOADER) {
assert (JProperties.class.getClassLoader().equals(new JProperties().getClass().getClassLoader()));
in = JProperties.class.getClassLoader().getResourceAsStream(name);
assert (in != null);
p.load(in);
// return new JProperties().getClass().getClassLoader().getResourceAsStream(name);
} else if (type == BY_SYSTEM_CLASSLOADER) {
in = ClassLoader.getSystemResourceAsStream(name);
assert (in != null);
p.load(in);
}
if (in != null) {
in.close();
}
return p;
}
// ---------------------------------------------- servlet used
/*
public static Properties loadProperties(ServletContext context, String path) throws IOException {
assert (context != null);
InputStream in = context.getResourceAsStream(path);
assert (in != null);
Properties p = new Properties();
p.load(in);
in.close();
return p;
}
*/
// ---------------------------------------------- support class
/**
* ResourceBundle Adapter class.
*/
public static class ResourceBundleAdapter extends Properties {
public ResourceBundleAdapter(ResourceBundle rb) {
assert (rb instanceof java.util.PropertyResourceBundle);
this.rb = rb;
java.util.Enumeration e = rb.getKeys();
while (e.hasMoreElements()) {
Object o = e.nextElement();
this.put(o, rb.getObject((String) o));
}
}
private ResourceBundle rb = null;
public ResourceBundle getBundle(String baseName) {
return ResourceBundle.getBundle(baseName);
}
public ResourceBundle getBundle(String baseName, Locale locale) {
return ResourceBundle.getBundle(baseName, locale);
}
public ResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader) {
return ResourceBundle.getBundle(baseName, locale, loader);
}
public Enumeration getKeys() {
return rb.getKeys();
}
public Locale getLocale() {
return rb.getLocale();
}
public Object getObject(String key) {
return rb.getObject(key);
}
public String getString(String key) {
return rb.getString(key);
}
public String[] getStringArray(String key) {
return rb.getStringArray(key);
}
protected Object handleGetObject(String key) {
return ((PropertyResourceBundle) rb).handleGetObject(key);
}
}
}
JPropertiesTest.java文件
/**
** 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 com.kindani.test;
import junit.framework.*;
import com.kindani.JProperties;
//import javax.servlet.ServletContext;
import java.util.Properties;
public class JPropertiesTest extends TestCase {
JProperties jProperties;
String key = "helloworld.title";
String value = "Hello World!";
public void testLoadProperties() throws Exception {
String name = null;
Properties p = new Properties();
name = "C:\\IDEAP\\Properties4Methods\\src\\com\\kindani\\test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_PROPERTIES);
assertEquals(value, p.getProperty(key));
name = "com.kindani.test.LocalStrings";
p = JProperties.loadProperties(name,JProperties.BY_RESOURCEBUNDLE);
assertEquals(value, p.getProperty(key));
assertEquals(value,((JProperties.ResourceBundleAdapter)p).getString(key));
name = "C:\\IDEAP\\Properties4Methods\\src\\com\\kindani\\test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_PROPERTYRESOURCEBUNDLE);
assertEquals(value, p.getProperty(key));
assertEquals(value,((JProperties.ResourceBundleAdapter)p).getString(key));
name = "\\com\\kindani\\test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_SYSTEM_CLASSLOADER);
assertEquals(value, p.getProperty(key));
name = "\\com\\kindani\\test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_CLASSLOADER);
assertEquals(value, p.getProperty(key));
name = "test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_CLASS);
assertEquals(value, p.getProperty(key));
}
/*
public void testLoadProperties2() throws Exception {
ServletContext context = null;
String path = null;
Properties p = null;
path = "/WEB-INF/classes/LocalStrings.properties";
p = JProperties.loadProperties(context, path);
assertEquals(value, p.getProperty(key));
}
*/
}
properties文件与JPropertiesTest.java文件相同的目录下
LocalStrings.properties文件
# $Id: LocalStrings.properties,v 1.1 2000/08/17 00:57:52 horwat Exp $
# Default localized resources for example servlets
# This locale is en_US
helloworld.title=Hello World!
requestinfo.title=Request Information Example
requestinfo.label.method=Method:
requestinfo.label.requesturi=Request URI:
requestinfo.label.protocol=Protocol:
requestinfo.label.pathinfo=Path Info:
requestinfo.label.remoteaddr=Remote Address:
requestheader.title=Request Header Example
requestparams.title=Request Parameters Example
requestparams.params-in-req=Parameters in this request:
requestparams.no-params=No Parameters, Please enter some
requestparams.firstname=First Name:
requestparams.lastname=Last Name:
cookies.title=Cookies Example
cookies.cookies=Your browser is sending the following cookies:
cookies.no-cookies=Your browser isn't sending any cookies
cookies.make-cookie=Create a cookie to send to your browser
cookies.name=Name:
cookies.value=Value:
cookies.set=You just sent the following cookie to your browser:
sessions.title=Sessions Example
sessions.id=Session ID:
sessions.created=Created:
sessions.lastaccessed=Last Accessed:
sessions.data=The following data is in your session:
sessions.adddata=Add data to your session
sessions.dataname=Name of Session Attribute:
sessions.datavalue=Value of Session Attribute:
**********************************************************
使用J2SE API读取Properties文件的六种方法
1。使用java.util.Properties类的load()方法
示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name));
Properties p = new Properties();
p.load(in);
2。使用java.util.ResourceBundle类的getBundle()方法
示例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());
3。使用java.util.PropertyResourceBundle类的构造函数
示例: InputStream in = new BufferedInputStream(new FileInputStream(name));
ResourceBundle rb = new PropertyResourceBundle(in);
4。使用class变量的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getResourceAsStream(name);
Properties p = new Properties();
p.load(in);
5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);
Properties p = new Properties();
p.load(in);
6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法
示例: InputStream in = ClassLoader.getSystemResourceAsStream(name);
Properties p = new Properties();
p.load(in);
补充
Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法
示例:InputStream in = context.getResourceAsStream(path);
Properties p = new Properties();
p.load(in);
完整的示例,可以参考附件文件
如何上传文件,谁知道请告诉以下。 只好把source都贴上来了
JProperties.java文件
/**
** 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 com.kindani;
//import javax.servlet.ServletContext;
import java.util.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
/**
* 使用J2SE API読取Properties文件的六種方法
* User: SYNFORM
* Date: 2005/07/12
* Time: 18:40:55
* To change this template use File | Settings | File Templates.
*/
public class JProperties {
public final static int BY_PROPERTIES = 1;
public final static int BY_RESOURCEBUNDLE = 2;
public final static int BY_PROPERTYRESOURCEBUNDLE = 3;
public final static int BY_CLASS = 4;
public final static int BY_CLASSLOADER = 5;
public final static int BY_SYSTEM_CLASSLOADER = 6;
public final static Properties loadProperties(final String name, final int type) throws IOException {
Properties p = new Properties();
InputStream in = null;
if (type == BY_PROPERTIES) {
in = new BufferedInputStream(new FileInputStream(name));
assert (in != null);
p.load(in);
} else if (type == BY_RESOURCEBUNDLE) {
ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());
assert (rb != null);
p = new ResourceBundleAdapter(rb);
} else if (type == BY_PROPERTYRESOURCEBUNDLE) {
in = new BufferedInputStream(new FileInputStream(name));
assert (in != null);
ResourceBundle rb = new PropertyResourceBundle(in);
p = new ResourceBundleAdapter(rb);
} else if (type == BY_CLASS) {
assert (JProperties.class.equals(new JProperties().getClass()));
in = JProperties.class.getResourceAsStream(name);
assert (in != null);
p.load(in);
// return new JProperties().getClass().getResourceAsStream(name);
} else if (type == BY_CLASSLOADER) {
assert (JProperties.class.getClassLoader().equals(new JProperties().getClass().getClassLoader()));
in = JProperties.class.getClassLoader().getResourceAsStream(name);
assert (in != null);
p.load(in);
// return new JProperties().getClass().getClassLoader().getResourceAsStream(name);
} else if (type == BY_SYSTEM_CLASSLOADER) {
in = ClassLoader.getSystemResourceAsStream(name);
assert (in != null);
p.load(in);
}
if (in != null) {
in.close();
}
return p;
}
// ---------------------------------------------- servlet used
/*
public static Properties loadProperties(ServletContext context, String path) throws IOException {
assert (context != null);
InputStream in = context.getResourceAsStream(path);
assert (in != null);
Properties p = new Properties();
p.load(in);
in.close();
return p;
}
*/
// ---------------------------------------------- support class
/**
* ResourceBundle Adapter class.
*/
public static class ResourceBundleAdapter extends Properties {
public ResourceBundleAdapter(ResourceBundle rb) {
assert (rb instanceof java.util.PropertyResourceBundle);
this.rb = rb;
java.util.Enumeration e = rb.getKeys();
while (e.hasMoreElements()) {
Object o = e.nextElement();
this.put(o, rb.getObject((String) o));
}
}
private ResourceBundle rb = null;
public ResourceBundle getBundle(String baseName) {
return ResourceBundle.getBundle(baseName);
}
public ResourceBundle getBundle(String baseName, Locale locale) {
return ResourceBundle.getBundle(baseName, locale);
}
public ResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader) {
return ResourceBundle.getBundle(baseName, locale, loader);
}
public Enumeration<String> getKeys() {
return rb.getKeys();
}
public Locale getLocale() {
return rb.getLocale();
}
public Object getObject(String key) {
return rb.getObject(key);
}
public String getString(String key) {
return rb.getString(key);
}
public String[] getStringArray(String key) {
return rb.getStringArray(key);
}
protected Object handleGetObject(String key) {
return ((PropertyResourceBundle) rb).handleGetObject(key);
}
}
}
JPropertiesTest.java文件
/**
** 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 com.kindani.test;
import junit.framework.*;
import com.kindani.JProperties;
//import javax.servlet.ServletContext;
import java.util.Properties;
public class JPropertiesTest extends TestCase {
JProperties jProperties;
String key = "helloworld.title";
String value = "Hello World!";
public void testLoadProperties() throws Exception {
String name = null;
Properties p = new Properties();
name = "C:\\IDEAP\\Properties4Methods\\src\\com\\kindani\\test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_PROPERTIES);
assertEquals(value, p.getProperty(key));
name = "com.kindani.test.LocalStrings";
p = JProperties.loadProperties(name,JProperties.BY_RESOURCEBUNDLE);
assertEquals(value, p.getProperty(key));
assertEquals(value,((JProperties.ResourceBundleAdapter)p).getString(key));
name = "C:\\IDEAP\\Properties4Methods\\src\\com\\kindani\\test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_PROPERTYRESOURCEBUNDLE);
assertEquals(value, p.getProperty(key));
assertEquals(value,((JProperties.ResourceBundleAdapter)p).getString(key));
name = "\\com\\kindani\\test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_SYSTEM_CLASSLOADER);
assertEquals(value, p.getProperty(key));
name = "\\com\\kindani\\test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_CLASSLOADER);
assertEquals(value, p.getProperty(key));
name = "test\\LocalStrings.properties";
p = JProperties.loadProperties(name, JProperties.BY_CLASS);
assertEquals(value, p.getProperty(key));
}
/*
public void testLoadProperties2() throws Exception {
ServletContext context = null;
String path = null;
Properties p = null;
path = "/WEB-INF/classes/LocalStrings.properties";
p = JProperties.loadProperties(context, path);
assertEquals(value, p.getProperty(key));
}
*/
}
properties文件与JPropertiesTest.java文件相同的目录下
LocalStrings.properties文件
# $Id: LocalStrings.properties,v 1.1 2000/08/17 00:57:52 horwat Exp $
# Default localized resources for example servlets
# This locale is en_US
helloworld.title=Hello World!
requestinfo.title=Request Information Example
requestinfo.label.method=Method:
requestinfo.label.requesturi=Request URI:
requestinfo.label.protocol=Protocol:
requestinfo.label.pathinfo=Path Info:
requestinfo.label.remoteaddr=Remote Address:
requestheader.title=Request Header Example
requestparams.title=Request Parameters Example
requestparams.params-in-req=Parameters in this request:
requestparams.no-params=No Parameters, Please enter some
requestparams.firstname=First Name:
requestparams.lastname=Last Name:
cookies.title=Cookies Example
cookies.cookies=Your browser is sending the following cookies:
cookies.no-cookies=Your browser isn't sending any cookies
cookies.make-cookie=Create a cookie to send to your browser
cookies.name=Name:
cookies.value=Value:
cookies.set=You just sent the following cookie to your browser:
sessions.title=Sessions Example
sessions.id=Session ID:
sessions.created=Created:
sessions.lastaccessed=Last Accessed:
sessions.data=The following data is in your session:
sessions.adddata=Add data to your session
sessions.dataname=Name of Session Attribute:
sessions.datavalue=Value of Session Attribute:
发表评论
-
Eclipse 插件集成myeclipse 7.0
2009-08-16 16:34 4148目前7.0的插件包没有找到下载地址,先使用updates直接从 ... -
如何使eclipse中subclipse插件的显示语言设置为英文
2009-08-16 14:13 5157虽然eclipse/myeclipse显示的语言为英文,但是网 ... -
疤痕实验--健康、积极的心态面对人生
2009-06-07 22:23 1442路易斯-拉皮德斯在他的 ... -
Java中的Connection Pool
2009-05-14 14:51 2818我们需要使用Connection Pool的情况都通常都是指网 ... -
Java程序员的推荐阅读书籍
2009-05-10 08:01 1138作为Java程序员来说,最痛苦的事情莫过于可以选择的范围太广, ... -
红油的做法
2009-05-03 18:43 17380 推荐 我想感受 ... -
应用整合中SSO的技术实现
2009-04-21 14:00 1098杨元 殷非 在税务行业信息化发展的关键阶段,应用整合已 ... -
SSO
2009-04-21 13:28 814SSO英文全称Single Sign On,单点登录。SSO是 ... -
Mylyn 简介 一个不错的eclipse工具
2009-04-19 23:45 2035Mylyn(旧称Mylar)是eclipse的一个插件,用 ... -
Eclipse 内存溢出OOM
2009-04-16 11:28 1511运行eclipse时出现错误提示框 错误提示大概如 ... -
MANIFEST.MF *** JAR中调用资源文件
2009-04-16 10:08 2524打开Java的JAR文件我们经 ... -
终于搞定word2007无法显示图片的问题
2009-04-02 10:41 4073最近突然发现我的word 2007无法显示图片了,任何图片、v ... -
一位软件工程师的6年总结
2009-03-31 16:20 888又是一年毕业时 ”,看 ... -
十招让你的工作效率up,up再up
2009-03-27 19:03 1191.确定方向 不走冤枉路 ... -
心理学家推荐3个10方法可助人做出正确决策
2009-03-10 21:19 721拿破仑选择了最能展示 ... -
Log4j配置[输出到文件]
2009-03-07 21:48 2460package net.meybo.mail;import o ... -
特殊字符编码大全
2009-03-04 14:33 1275" " & &a ... -
笔记阅读摘要(值得每天多看几遍)
2009-02-18 20:09 8281. A web application uses a de ... -
程序员四大忌
2009-02-17 16:46 769一忌:轻易言败,没有 ... -
J2EE架构分析
2009-02-16 22:48 1769J2EE架构是当前 ...
相关推荐
### J2SE API读取Properties文件六种方法 在Java开发过程中,经常需要读取配置文件来获取系统运行时所需的参数或配置信息。`Properties`类是Java标准库中的一个非常重要的工具类,用于处理键值对形式的配置数据。...
本文将详细讲解使用J2SE API来读取Properties文件的六种方法。 1. **使用java.util.Properties类的load()方法** 这是最基本的方法,通过`FileInputStream`打开文件,然后使用`Properties`类的`load()`方法加载内容...
为了在Python中读取这样的文件,我们可以创建一个名为`Properties`的类,该类包含两个方法:`__init__`和`getProperties`。`__init__`用于初始化类实例,并接收文件路径作为参数;`getProperties`方法负责打开文件,...
### Java读取Properties文件的六种方法 在Java开发中,`Properties` 文件常用于存储配置信息,如数据库连接字符串、应用配置等。正确且高效地读取这些配置文件对于程序运行至关重要。本文将详细介绍六种不同的方法...
本文将详细介绍Java中读取Properties文件的六种方法,以及在Web应用环境下的一种额外方式。 ### 方法一:使用`java.util.Properties`类的`load()`方法 这是最直接的方法,通过创建`Properties`对象并调用其`load()...
如果你需要在用户选择文件后读取.properties文件,可以利用FileReader API的`readAsText()`方法。一旦读取完成,会触发`onload`事件,你可以在这个事件回调中获取到文件内容。 ```javascript let fileInput = ...
### API读取Properties文件的六种方法 在Java开发中,`Properties` 文件常用于存储配置信息,如数据库连接字符串、应用配置等。通过API读取这些文件是开发者经常遇到的任务之一。本文将详细介绍六种使用J2SE API...
### Java读取Properties文件的六种方法 在Java开发中,`Properties`类是一个非常实用且常见的工具类,主要用于管理程序中的配置信息。通常情况下,这些配置信息会被存储在一个`.properties`文件中,并通过`...
在Java编程中,Properties文件是一种常用的配置文件格式,用于存储应用程序的配置参数或者环境设置。这些文件通常以键值对的形式存在,例如`key=value`。读取Properties文件是Java开发中的常见操作,特别是在需要...
本文将详细介绍六种使用J2SE API(Java标准版API)来读取Properties文件的方法,帮助开发者更好地理解和操作这类文件。 1. 使用Properties类的load()方法 这是最基础且常用的方法,直接通过InputStream读取...
1. **properties文件结构** `properties`文件的结构非常简单,每行代表一个键值对,键和值之间用等号`=`或冒号`:`分隔。例如: ``` username=admin password=123456 database.url=jdbc:mysql://localhost:3306/...
properties文件读写操作
`java.util.Properties`是Java提供的一种用于处理`.properties`文件的类,它可以加载、保存键值对,并提供获取和设置键值的方法。`load()`方法用于从输入流加载键值对,`getProperty()`用于获取特定键对应的值。 4...
C#提供了一种简单有效的方法来操作配置文件中的属性(Properties),即通过`System.Configuration`命名空间下的`ConfigurationManager`类以及`Properties.Settings`类。 #### 一、基础知识介绍 1. **配置文件**: 在...
本文将详细介绍三种在Java中读取properties文件的方法。 1. 使用Properties类 Java的java.util.Properties类是专门用来处理.properties文件的。下面是一个简单的示例: ```java import java.io.FileInputStream; ...
### Java读写Properties配置文件详解 #### 一、引言 在Java开发中,`Properties`类被广泛用于处理各种类型的配置文件。这些文件通常包含了应用程序运行时所需的配置信息,如数据库连接信息、系统参数等。`...