JAvaはpropertiesファイルを読み込む方法
757 ワード
resoucesの下にconfフォルダを作成します.testが入っています.peropertiesファイル、内容は以下の通りです
abc=33
dd=44
は、次のjavaクラスで読み込みます.import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Test {
private static Properties properties = new Properties();
private void testRead() throws IOException{
InputStream inputStream = this.getClass().getClassLoader()
.getResourceAsStream("conf/test.properties");
properties.load(inputStream);
System.out.println(properties.get("abc"));
}
public static void main(String[] args) throws IOException {
Test test = new Test();
test.testRead();
}
}
出力結果:33
は成功したことを示しています.