java项目中读取src目录下的文件
private void getUser(String tmpfile){
Properties props = new Properties();
props.load(DbTask.class.getClassLoader().getResourceAsStream(
tmpfile));
return props.getProperty("user");
}
方法说明:
tmpfile是传入的需要读取的文件名
这个文件一定要跟DbTask类,在一个包下面
调用:
getUser("/test.ini"); ==>abc
test.ini文件内容:
user=abc
pwd=123
如果不在同一个包中,那么只要把 getUser("/test.ini");改成 getUser("/包/test.ini"); ==> eg. getUser("/cn/test/sample/test.ini");
java项目中读取src目录下的文件的更多相关文章
- [Java] 在 jar 文件中读取 resources 目录下的文件
注意两点: 1. 将资源目录添加到 build path,确保该目录下的文件被拷贝到 jar 文件中. 2. jar 内部的东西,可以当作 stream 来读取,但不应该当作 file 来读取. 例子 ...
- WEB编程中获取src目录下的文件(没有src目录)
这种情况遇见的会比较多,像一个WEB工程,如果在src下面写了一个xml或者一些其它的文件,当工程发布到服务器时,web程序是在tomcat等服务器下运行这个程序的,这个时候,程序目录里面并没有src ...
- iOS案例:读取指定目录下的文件列表
// // main.m // 读取指定目录下的文件列表 // // Created by Apple on 15/11/24. // Copyright © 2015年 Apple. All rig ...
- Python 读取某个目录下的文件
读取某个目录下的文件,如'/Users/test/test_kmls'目录下有test1.txt.test2.txt. 第一种方法读出的all_files是test1.txt.test2.txt im ...
- SpringBoot读取资源目录下的文件
需要读取resources目录下的文件,那么方法如下: 假设在资源目录下的template目录下有一个文件a.txt,获取到文件流的方式 InputStream stream = this.getCl ...
- Maven项目中读取src/main/resources目录下的配置文件
在Maven项目的开发中,当需要读取src/下的配置文件时,该怎么做? 我们假设Resources下有一个文件名为kafka.properties的配置文件(为什么用kafka.properties, ...
- java web项目中 获取resource路径下的文件路径
public GetResource{ String path = GetResource.class.getClassLoader().getResource("xx/xx.txt&quo ...
- IDEA中读取 resource目录下文件
1. 资源文件 2. 加载文件 public void test() { try { System.out.println("begin test"); String filepa ...
- java 读取固定目录下的文件(和上篇差点儿相同)
package gao.org; import java.io.FileNotFoundException; import java.io.IOException; import java.io.Fi ...
随机推荐
- sift算法中翻译的第11页中比值问题
没下载下来... http://download.csdn.net/detail/shwaicy1314/7320695 原文翻译.应该是 2004年lowe写的吧 第八页 图C展示的 是小于0.03 ...
- Sublime Text shift+ctrl妙用
1 :按住shift+ctrl然后按←或→可快速选中一行中的某一部分,相当于双击鼠标选中. 当你想在代码末尾加注释的话,这个方法很好用 输入文字->光标移到文字末尾->按住shift+ct ...
- java 远程调试
在java 命令上加入 -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y suspend=y 配置的端口时候要保证没有被占用
- Linux chmod command
@ chmod改变一个或多个文件的存取模式 chmod [options] mode files 只有文件属主或特殊用户才能使用该功能来改变文件存取模式.mode可以是数字形式或who opcode ...
- Student
using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace PersonD ...
- Table of Contents - Ehcache
Ehcache 2.9.x API Developer Guide Key Classes and Methods Basic Caching Cache Usage Patterns Searchi ...
- Jfinal----Handler之责任链设计模式
Jfinal handler的处理采用了责任链设计模式 有关责任链模式,推荐看: <JAVA与模式>之责任链模式 1.实现Handler只需要继承Handler public class ...
- aspcms中if判断语句的运用
1.<h3 {if:"[list:isrecommend]"="1"} style="color:red;"{end if}>& ...
- C#去除HTML标签(转)
public static string ReplaceHtmlTag(string html, int length = 0) { string strText = System.Text.Regu ...
- 如何使用10个小时搭建出个人域名而又Geek的独立博客?
1.安装准备软件 Node.js.Git.GitHub DeskTop(前两个必须安装,后者可选) 2.本地搭建hexo框架.配置主题.修改参数.实现本地测试预览 3.链接GitHub.实现在线预览 ...