根据输入的IP来更改磁盘的db.properties
程序员文章站
2022-07-14 20:11:37
...
由于使用别人电脑的数据库。所以在他重启电脑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
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