Java中属性类及属性文件的定义分别是什么

Python011

Java中属性类及属性文件的定义分别是什么,第1张

没有属性类这个词吧,应该是类属性跟类方法之类的吧。如果是类属性就是直接在类体里定义的

用static修饰的变量实例变量则是在类体里定义但没有static修饰的。类方法是有static修饰的方法。因为static是在类初始化时已经生成的。

那是属性的意思啊

就是我说的类属性跟实例变量了。

java.util.Properties

类中有方法

Object

setProperty(String key,

String value)

Calls the Hashtable method put.

void

store(OutputStream out,

String comments)

Writes this property list (key and element pairs) in this

Properties table to the output stream in a format suitable

for loading into a Properties table using the

load(InputStream) method.

void

store(Writer writer,

String comments)

Writes this property list (key and element pairs) in this

Properties table to the output character stream in a

format suitable for using the load(Reader)

method.

void

storeToXML(OutputStream os,

String comment)

Emits an XML document representing all of the properties contained

in this table.

void

storeToXML(OutputStream os,

String comment,

String encoding)

Emits an XML document representing all of the properties contained

in this table, using the specified encoding.

private static String driver =null

private static String url = null

private static String user = null

private static String password = null

private static BasicDataSource ds

static{

//读取程序外的.properties 文件

//需要.properties文件的包路径

Properties props = new Properties()

try {

String path ="db.properties"

props.load(

DBUtils.class.getResourceAsStream(path)

)

//properties对象.getProperty("字符串")

driver=props.getProperty("driver")

url=props.getProperty("url")

user=props.getProperty("user")

password=props.getProperty("password")

ds = new BasicDataSource()

ds.setDriverClassName(driver)

ds.setUrl(url)

ds.setUsername(user)

ds.setPassword(password)

Class.forName(driver)

} catch (Exception e) {

e.printStackTrace()

}

}

这是一个JDBC读取配置文件连接数据库的示例代码,供参考!