PropertiesTest类文件
package properties;
import java.io.IOException;
import java.util.Properties;
import junit.framework.TestCase;
import junit.textui.TestRunner;
public class PropertiesTest extends TestCase {
public void testproperties() {
Properties props = new Properties();
String _url = null;
String _name = null;
try {
//加载文件
props.load(PropertiesTest.class
.getResourceAsStream("/ftpService.properties"));
//根据文件中的url属性得到对应的属性值
_url = props.getProperty("url");
//根据文件中的name属性得到对应的属性值
_name = props.getProperty("name");
System.out.print(_url+_name);
} catch (IOException e) {
}
}
public static void main(String[] args) throws Exception {
TestRunner.run(PropertiesTest.class);
}
}
ftpService.properties文件
url=http\://localhost/clip-web/hessian/hessianService
name=123456
要注意
ftpService.properties文件属性与值格式
属性 = 值
属性 = 值
一定要换行