
正文
java写配置文件代码,java配置教程
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java配置文件怎么写?
参考java.util.Properties对象进行书写,另外可以在网上找一写辅助书写材料。
代码:
public static void main(String[] args) {
Properties p = new Properties();
p.setProperty("id", "user1");
p.setProperty("password", "123456");
try{
PrintStream stm = new PrintStream(new File("e:\test.properties"));
p.list(stm);
} catch (IOException e) {
e.printStackTrace();
}
}
相关问答
Q1: java配置文件怎么写
web.xml配置如下:
?xml version="1.0" encoding="UTF-8" ?
- web-app version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation=" "
- filter
filter-nameMyFilter/filter-name
filter-classgame.filter.MyFilter/filter-class
/filter
- filter-mapping
filter-nameMyFilter/filter-name
url-pattern/*/url-pattern
/filter-mapping
- welcome-file-list
welcome-fileindex.jsp/welcome-file
/welcome-file-list
/web-app
过滤器类如下:
package game.filter;
import java.io.IOException;
import javax.servlet.*;
public class MyFilter implements Filter {
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
chain.doFilter(request, response);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
}
Q2: Java中的properties配置文件怎么写,代码
public static void main(String[] args) {
Properties p = new Properties();
p.setProperty("id", "user1");
p.setProperty("password", "123456");
try{
PrintStream stm = new PrintStream(new File("e:\test.properties"));
p.list(stm);
} catch (IOException e) {
e.printStackTrace();
}
}








