IntelliJ IDEA多屏后窗口不顯示問題解決(用工具一鍵解決)


IDEA 在接入外接屏且擴展的情況下,如果突然拔掉外接屏,就可能會產生IDEA 整個窗口只在屏幕的右側顯示一點點邊框且無法拖拽到當前屏幕的情況。

在不再次接入外接屏的情況下,想要把IDEA窗口拖拽回當前屏幕,可以找到項目中.idea 文件夾下的workspace.xml 文件
全文搜索ProjectFrameBounds 關鍵字,修改x和y的值為0或者直接將name="x",name="y"的這兩行刪除即可,然后重啟IDEA即可

 

 以上轉自 https://blog.csdn.net/zhj870975587/article/details/80168736


因為經常遇到這種情況,所以自己寫了個java 小工具,一鍵刪除 name="x",name="y" 這兩行記錄,同時生成一個原始文件的.bak 文件,入參只需要文件路徑

其中的核心代碼邏輯示例如下:

(標簽: 使用Java 實現刪除某個文件中 包含特定字符的行)

  1 import java.io.*;
  2 
  3 /**
  4  * @author jiashubing
  5  * @since 2019/5/22
  6  */
  7 public class DeleteLine {
  8     public static void main(String[] args) {
  9         String path = "C:\\Users\\jiashubing\\Desktop\\ttt\\workspace.xml";
 10         deleteLine(path);
 11     }
 12 
 13     private static String deleteLine(String path) {
 14         int a = path.lastIndexOf('/');
 15         int b = path.lastIndexOf('\\');
 16         if (a < 0 && b < 0) {
 17             return "沒有目錄分隔符";
 18         }
 19 
 20         //刪除原來的備份文件
 21         String bakpath = path + ".bak";
 22         if (deleteFile(bakpath)) {
 23             return "刪除原始的備份文件失敗,備份文件為:" + bakpath;
 24         }
 25 
 26         String bakpath2 = path + ".bak2";
 27         if (deleteFile(bakpath2)) {
 28             return "刪除原始的臨時備份文件失敗,備份文件為:" + bakpath2;
 29         }
 30 
 31         //創建臨時備份文件
 32         File bakFile2 = new File(bakpath2);
 33         boolean nFlag = false;
 34         try {
 35             nFlag = bakFile2.createNewFile();
 36         } catch (IOException e) {
 37             return "創建臨時備份文件失敗,備份文件為:" + bakpath2 + "  錯誤信息為:" + e.getMessage();
 38         }
 39         if (!nFlag) {
 40             return "創建臨時備份文件失敗,備份文件為:" + bakpath2;
 41         }
 42 
 43         String ans = getAns(path);
 44         if (ans == null) {
 45             return "讀取並修改原始文件失敗";
 46         }
 47 
 48         if (!addNewFile(bakpath2, ans)) {
 49             return "將修改后的內容寫入到新文件失敗";
 50         }
 51 
 52         File oldFile = new File(path);
 53         boolean mvFlag = oldFile.renameTo(new File(bakpath));
 54         if (!mvFlag) {
 55             return "將原始文件重命名成備份文件失敗";
 56         }
 57 
 58         boolean mvFlag2 = bakFile2.renameTo(new File(path));
 59         if (!mvFlag2) {
 60             return "將臨時備份文件重命名成原始文件失敗";
 61         }
 62 
 63         return "執行成功";
 64     }
 65 
 66     private static boolean deleteFile(String bakpath) {
 67         File bakFile = new File(bakpath);
 68         if (bakFile.exists() && bakFile.isFile()) {
 69             boolean delFlag = bakFile.delete();
 70             if (!delFlag) {
 71                 return true;
 72             }
 73         }
 74         return false;
 75     }
 76 
 77     private static String getAns(String path) {
 78         File oldFile = new File(path);
 79         if (!oldFile.exists() || !oldFile.isFile()) {
 80             return null;
 81         }
 82 
 83         StringBuilder ans = new StringBuilder();
 84         String encoding = "UTF-8";
 85         try (InputStreamReader read = new InputStreamReader(
 86                 new FileInputStream(oldFile), encoding);
 87              BufferedReader bufferedReader = new BufferedReader(read)) {
 88             String lineTxt = null;
 89             while ((lineTxt = bufferedReader.readLine()) != null) {
 90                 if (lineTxt.contains("name=\"x\"") || lineTxt.contains("name=\"y\"")) {
 91                     continue;
 92                 }
 93                 ans.append(lineTxt + "\n");
 94             }
 95         } catch (Exception e) {
 96             return null;
 97         }
 98 
 99         return ans.toString();
100     }
101 
102     private static boolean addNewFile(String path, String ans) {
103         File file = new File(path);
104 
105         try (Writer out = new FileWriter(file)) {
106             out.write(ans);
107         } catch (IOException e) {
108             return false;
109         }
110 
111         return true;
112     }
113 }

 

原創文章,歡迎轉載,轉載請注明出處!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM