java读注册表 备份mysql
程序员文章站
2022-05-10 16:51:24
...
mport java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintStream; import ca.beq.util.win32.registry.RegistryKey; import ca.beq.util.win32.registry.RegistryValue; import ca.beq.util.win32.registry.RootKey; public class ReadReg { public static String getPath() { RegistryKey r = new RegistryKey(RootKey.HKEY_LOCAL_MACHINE, "Software\\MySQL AB\\MySQL Server 6.0"); if(r.hasValue("Location")) { RegistryValue v = r.getValue("Location"); System.out.println(v.getStringValue()); return v.getStringValue(); } return ""; } public static void main(String[] args) { try { startPing(getPath()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void startPing(String path) throws IOException{ InputStreamReader in = null; BufferedReader output = null; OutputStreamWriter writer = null; try { String exeName = path + "\\bin\\mysqldump.exe -uroot -p123 test1"; final Process process = Runtime.getRuntime().exec(exeName); String result = ""; // Runnable rr = null;//new ReadErrorStream(process, result); // rr = new ReadErrorStream(process, result); // Thread t = new Thread(rr); // t.start(); // System.out.print(result); in = new InputStreamReader(process.getInputStream(), "utf8"); output = new BufferedReader(in); String line = null; FileOutputStream fout = new FileOutputStream( "c:\\222.sql"); writer = new OutputStreamWriter(fout, "utf8"); while ((line = output.readLine()) != null) { System.out.println(line); writer.write(line+"\n"); } writer.flush(); int exitValue = process.exitValue(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } finally { writer.close(); output.close(); in.close(); } } // private static class ReadErrorStream implements Runnable { // private Process process; // // private String errorInput; // // public ReadErrorStream(Process tprocess, String input) { // this.process = tprocess; // this.errorInput = input; // } // // public void run() { // try { // BufferedReader error = new BufferedReader( // new InputStreamReader(process.getErrorStream())); // String line = null; // StringBuffer readInput = new StringBuffer(); // while ((line = error.readLine()) != null) { // readInput.append(line); // } // synchronized (errorInput) { // errorInput = readInput.toString(); // } // } catch (Exception e) { // e.printStackTrace(); // } // } // } }
下一篇: 为何说唐朝在唐昭宗时就已经名存实亡了?