根据输入的IP来更改磁盘的db.properties

由于使用别人电脑的数据库。所以在他重启电脑IP被改掉的时候,本机的db.properties里面的IP必须要改成对应的。特此编码:
SysDBTest.java


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;

public class SysDBTest {

/**
* @author xum 2010-10-11
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要修改的IP...");
String sysIP = scanner.nextLine();
update(sysIP);
System.out.println("修改完成!");

}
/**
* 根据孙印生的电脑修改Windchill db.properties中的IP信息
* @author xum 2010-10-12
* @throws Exception
*/
public static void update(String args) throws Exception{

//新建输入流
File file = new File("D:/ptc/Windchill_9.1/Windchill/db/db.properties");
FileInputStream fis = new FileInputStream(file);

//读写properties
Properties p = new Properties();
// D:/ptc/Windchill_9.1/Windchill/db/db.properties";
p.load(fis);
String v1 = p.getProperty("wt.cognos.endpointUrl");
String v2 = p.getProperty("wt.pom.jdbc.host");
String v3 = p.getProperty("wt.pom.serviceName");
System.out.println(v1+"sss");
String newStr1 = v1.substring(v1.indexOf("//")+2,v1.lastIndexOf(":"));
String result1 = v1.replace(newStr1,args);
p.setProperty("wt.cognos.endpointUrl", result1);

p.setProperty("wt.pom.jdbc.host", args);

String newStr2 = v3.substring(0,v3.indexOf(":"));
String result2 = v3.replace(newStr2, args);
p.setProperty("wt.pom.serviceName", result2);

//新建输出流并保存
FileOutputStream fos = new FileOutputStream(file);
p.save(fos, null);


}

}

导出changeip.jar后,新建bat文件,输入:
java -jar changeip.jar
pause
save-run
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值