|
1 | 1 | package com.xwintop.xJavaFxTool.services.debugTools; |
2 | 2 |
|
| 3 | +import com.sun.jna.Platform; |
3 | 4 | import com.xwintop.xJavaFxTool.controller.debugTools.SwitchHostsToolController; |
4 | 5 | import com.xwintop.xcore.util.SystemInfoUtil; |
5 | 6 | import com.xwintop.xcore.util.javafx.TooltipUtil; |
@@ -33,16 +34,22 @@ public class SwitchHostsToolService { |
33 | 34 | private String localHost2String = "# 方案二\n"; |
34 | 35 |
|
35 | 36 | public void reloadSystemHosts() throws Exception { |
36 | | - String fileName = SystemInfoUtil.getHostsFilePath(); |
37 | | - String systemHostString = FileUtils.readFileToString(new File(fileName),"utf-8"); |
| 37 | + String fileName = null; |
| 38 | + if (Platform.isWindows()) { |
| 39 | + fileName = "C://WINDOWS//system32//drivers//etc//hosts"; |
| 40 | + } else { |
| 41 | + fileName = "/etc/hosts"; |
| 42 | + } |
| 43 | +// String fileName = SystemInfoUtil.getHostsFilePath(); |
| 44 | + String systemHostString = FileUtils.readFileToString(new File(fileName), "utf-8"); |
38 | 45 | switchHostsToolController.getHostTextArea().setText(systemHostString); |
39 | 46 |
|
40 | 47 | } |
41 | 48 |
|
42 | 49 | public void editAction() throws Exception { |
43 | 50 | String fileName = SystemInfoUtil.getHostsFilePath(); |
44 | 51 | String systemHostString = switchHostsToolController.getHostTextArea().getText(); |
45 | | - FileUtils.writeByteArrayToFile(new File(fileName),systemHostString.getBytes()); |
| 52 | + FileUtils.writeByteArrayToFile(new File(fileName), systemHostString.getBytes()); |
46 | 53 | TooltipUtil.showToast("保存配置成功"); |
47 | 54 | } |
48 | 55 |
|
|
0 commit comments