社区
Web 开发
帖子详情
如何读取properties中的数据
xiaolihui333
2003-11-11 09:27:34
为什莫不能读properties中数据
...全文
595
2
打赏
收藏
如何读取properties中的数据
为什莫不能读properties中数据
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
javaprogramlover
2003-12-11
打赏
举报
回复
学习中!
wellsoon
2003-11-11
打赏
举报
回复
1.先写jsp代码如下:
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*"%>
<html>
<head>
<title>
引用资源文件的演示
</title>
</head>
<body bgcolor="#ffffff">
<h1>
引用资源文件的演示例子
</h1>
<%
String sDriver="";
String sUser="";
String sPasswd="";
String sDsn="";
try
{
ResourceBundle res;
res = ResourceBundle.getBundle("testres");
sDriver = res.getString("DRIVER");
sUser = res.getString("USERID");
sPasswd = res.getString("PASSWORD");
sDsn= res.getString("DSN");
}
catch(Exception e){out.println("Error:ResFileNotFound!");return;}
out.println("DRIVER为:"+sDriver);
out.println("<br>USERID为"+sUser);
out.println("<br>PASSWORD为"+sPasswd);
out.println("<br>DSN为:"+sDsn);
%>
</body>
</html>
2.建立资源文件
主菜单->File->New File->Type选择properties,文件名testres,存放路径随便选择。
点击OK即可。
3.编辑资源文件.
写如以下内容:
DRIVER=COM.ibm.db2.jdbc.net.DB2Driver
DSN=jdbc:db2://192.168.11.3:38868/mser
USERID=db2inst1
PASSWORD=11c1mari
保存。
4.在工程里添加资源文件。
主菜单->Project->Add Files/Packages->选择刚才创建的testres.properties。
点击OK即可。
5.运行jsp,此时页面输出为:
引用资源文件的演示例子
DRIVER为:COM.ibm.db2.jdbc.net.DB2Driver
USERID为db2inst1
PASSWORD为11c1mari
DSN为:jdbc:db2://192.168.11.3:38868/mser
资源文件添加成功了!!!
2003-9-8 12:44:00
修改笔记 发表评语???
2003-9-8 19:12:42 关于存储.properties文件的操作参考连接:
http://www.javaresearch.org/article/showarticle.jsp?column=1&thread=4289
package beanservlettest;
import java.util.*;
import java.io.*;
public class poptest {
public poptest() {
}
public static void main(String[] args) {
poptest poptest1 = new poptest();
try{ poptest1.saveProperties();}
catch(Exception e){
System.out.println("出错了:" + e.getMessage());
}
}
private void saveProperties() throws Exception {
Properties prop = new Properties();
FileOutputStream fos;
FileInputStream fis;
try {
fis = new FileInputStream(new File("c:\\config.properties"));
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
throw new Exception("File config.properties NOT found!");
}
try {
prop.load(fis);
}
catch (IOException ex1) {
ex1.printStackTrace();
throw new Exception("Error while read from config.properties!");
}
System.out.println("other is:" + prop.getProperty("other"));
prop.setProperty("setting1", "value2");
System.out.println("other is:" + prop.getProperty("other"));
try {
fos = new FileOutputStream(new File("c:\\config.properties"));
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
throw new Exception("File config.properties NOT found!");
} //save the properties
try {
prop.store(fos, null);
}
catch (IOException e) {
e.printStackTrace();
throw new Exception("Error when save the config.properties.");
}
}
}
Spring Boot
读取
properties
配置文件
中
的
数据
在实际项目
中
,当项目需要注入的变量值很多时,上述所述的两种方法工作量会变得比较大,这时候我们通常使用基于类型安全的配置方式,将
properties
...
读取
properties
配置文件时,默认
读取
的是application.
properties
。
java
properties
读取
中
文_Java
读取
properties
文件
中
文乱码
Java
读取
properties
文件
中
文乱码之前
读取
properties
配置文件时候全都是英文或者数字之类的,最近项目有个需求要
properties
配置文件
中
有
中
文字符存在,那么
读取
java
properties
文件的时候如果value是
中
文,结果出现...
读取
properties
配置文件
中
的
数据
Spring Boot最常用的3种
读取
properties
配置文件
中
数据
的方法: 1.使用@Value注解
读取
直接通过@Value注解注入一个配置信息到Spring管理的 Bean
中
。默认
读取
的是application.
properties
。 application....
java
读取
properties
文件的
数据
1、首先,先新建一个
properties
文件,以常用的配置
数据
库参数的
properties
为例: ...2、使用类加载器
读取
properties
文件的内容 public class App { private static
Properties
properties
= new Prop
小程序 Component
读取
properties
中
的
数据
【代码】小程序 Component
读取
properties
中
的
数据
。
Web 开发
81,092
社区成员
341,716
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章