在代码开始前,我们先了解一下操作系统对对注册表的相关命令与操作
REG Operation [参数列表]
Operation [ QUERY | ADD | DELETE | COPY |
SAVE | LOAD | UNLOAD | RESTORE |
COMPARE | EXPORT | IMPORT ]
返回代码: (除了 REG COMPARE)
0 - 成功
1 - 失败
要得到有关某个操作的帮助,请键入:
REG Operation /?
例如:
REG QUERY /?
REG ADD /?
REG DELETE /?
REG COPY /?
REG SAVE /?
REG RESTORE /?
REG LOAD /?
REG UNLOAD /?
REG COMPARE /?
REG EXPORT /?
REG IMPORT /?
REG Operation [参数列表]
Operation [ QUERY | ADD | DELETE | COPY |
SAVE | LOAD | UNLOAD | RESTORE |
COMPARE | EXPORT | IMPORT ]
返回代码: (除了 REG COMPARE)
0 - 成功
1 - 失败
要得到有关某个操作的帮助,请键入:
REG Operation /?
例如:
REG QUERY /?
REG ADD /?
REG DELETE /?
REG COPY /?
REG SAVE /?
REG RESTORE /?
REG LOAD /?
REG UNLOAD /?
REG COMPARE /?
REG EXPORT /?
REG IMPORT /?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @description 本程序实现了读取注册表分支:HKEY_CURRENT_USER/Software/ODBC/ODBC.INI/ODBC Data Sources到内存的操作
*/
public class getRegToMemery {
public static void main(String []args){
try {
Process ps = null;
ps = Runtime
.getRuntime()
.exec(
"reg query /"HKEY_CURRENT_USER//Software//ODBC//ODBC.INI//ODBC Data Sources/"");
ps.getOutputStream().close();
InputStreamReader i = new InputStreamReader(ps.getInputStream());
String line;
BufferedReader ir = new BufferedReader(i);
while ((line = ir.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}