潍坊市网站优化,广州网站制作哪家公司好,在哪网站可以做农信社模拟试卷,网页设计及网站建设在线作业maven工程的代码布局如下#xff1a;在resources下面有一个资源文件test.properties#xff0c;现在的目标要在Java代码中读取该资源文件中的内容。
test.properties资源文件的内容如下#xff1a;
Java代码如下#xff1a;
package com.thb;import java.io.BufferedR…maven工程的代码布局如下在resources下面有一个资源文件test.properties现在的目标要在Java代码中读取该资源文件中的内容。
test.properties资源文件的内容如下
Java代码如下
package com.thb;import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;import java.util.Map.Entry;public class Demo {public static void main(String[] args) {String fileName /test.properties;URL url Demo.class.getResource(fileName); String path url.getPath();try {BufferedReader in new BufferedReader(new InputStreamReader(new FileInputStream(path)));Properties pro new Properties();pro.load(in);for (EntryObject, Objectentry : pro.entrySet()) {System.out.println(entry.getKey() entry.getValue());}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}
1在cmd下运行mvn compile进行编译 2运行mvn exec:java -Dexec.mainClasscom.thb.Demo执行 从输出可以看出得到了正确的结果。