|
src
|
t090417
|
test.properties
Read.java
test.properties:
TEST=test
Read.java:
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.IOException
import java.util.Properties
public class Read {
public static String TEST
private static Properties loadPropertyFile() throws FileNotFoundException,IOException{
Properties properties = new Properties()
FileInputStream fs = new FileInputStream("src/t090417/test.properties")
properties.load(fs)
return properties
}
public static void loadProperty(){
try{
Properties properties = loadPropertyFile()
TEST = properties.getProperty("TEST")
System.out.println("read from properties: "+TEST)
}catch(Exception e){
e.printStackTrace()
}
}
public static void main(String[] args) {
loadProperty()
}
}
相对路径就是你建立文件后文件就放在你部署到tomcat项目的文件夹中。建立文件很简单:比如:File file = new File("a.txt")
这样项目下就有这个文件了。
绝对路径就是
File file = new File("d:/a.txt")
这样文件就在d盘下了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)