使用脚本运行程序读取.properties文件
来源:互联网 发布:final cut mac 破解 编辑:程序博客网 时间:2024/05/16 17:53
1).properties文件
name=xiaoxiage=24
2)读取代码
import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class PropertiesTest {private Properties defaultProperties = new Properties();public PropertiesTest(){}private void getProperties(String properties){try {InputStream in = new FileInputStream(properties);this.defaultProperties.load(in);in.close();String name = this.defaultProperties.getProperty("name");System.out.println("name: " + name);int age = Integer.valueOf(this.defaultProperties.getProperty("age"));System.out.println("age: " + age);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public static void main(String[] args){if ((args == null) || (args.length == 0)) {System.out.println("java -jar propertiesTest.jar [属性文件]");return;}String TEST_HOME = null;try {TEST_HOME = System.getenv("TEST_HOME");} catch (Exception e) {}String testPro = args[0];System.out.println("testPro: " + testPro);String properties = TEST_HOME + File.separator + "conf" + File.separator + "pro.properties"PropertiesTest1 pt = new PropertiesTest1();pt.getProperties(properties);}}
3)运行脚本文件start.sh
#!/bin/bash#TEST_HOME="/home/logmonitor/LogStat"export TEST_HOME=/home/xiaoxi/testTESTPRO="hello"echo "java -jar $TEST_HOME/core/providerLogMonth.jar $TESTPRO"nohup java -jar $TEST_HOME/core/providerLogMonth.jar $TESTPRO > $TEST_HOME/log/test.log 2>&1 &
4)输出结果
testPro: helloname: xiaoxiage: 24
注:
1)将程序打成 jar包和pro.properties文件添加到Linux服务器上;
2)使用脚本start.sh运行程序,sh start.sh;
3)TESTPRO为运行程序时添加的参数;
4)程序将TEST_HOME作为环境变量读取,TEST_HOME = System.getenv("TEST_HOME");
5) File.separetor为文件分隔符;
6)脚本中echo为运行程序时的回显语句;
7)如果脚本是在Windows环境先编写的放到Linux环境时需执行dos2unix start.sh命令转换编码格式;
- 使用脚本运行程序读取.properties文件
- Spring使用程序方式读取properties文件
- Spring使用程序方式读取properties文件
- Spring使用程序方式读取properties文件【笔记】
- java 读取properties文件,运用 使用properties
- 使用Properties读取XML文件
- 使用spring读取properties文件
- java程序中读取properties文件
- Properties读取properties文件
- Properties 读取 Properties文件
- 使用Properties记录程序运行次数
- 使用J2SEAPI读取Properties文件的方法
- 使用common-configuration读取xml,properties文件
- 使用common-configuration读取xml,properties文件
- 使用单例模式读取Properties文件
- 使用PropertyPlaceholderConfigurer读取.properties文件(1)
- Spring 使用@PropertySource读取properties文件
- 使用java.util.Properties读取文件
- Wiki关于Dirichlet分布
- 【js】json格式的javascript对象
- 程序员必知的8大排序(三)-------冒泡排序,快速排序(java实现)
- 问题源1——滤波理论与应用
- iptables实现端口转发的过程
- 使用脚本运行程序读取.properties文件
- SIFT特征详细描述
- C#中跨线程访问控件问题解决方案
- DirectX9 SDK Samples(14) EffectParam Sample(1)
- const 用法
- Crypto库实现PKCS7签名与签名验证
- signal的全集和信号handler.txt
- Objective-c Callbacks(转载)
- In-place Merge Sort (原地归并排序)