zoukankan      html  css  js  c++  java
  • 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 + "
    ");
     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 }

    原创文章,欢迎转载,转载请注明出处!

  • 相关阅读:
    [No0000139]轻量级文本编辑器,Notepad最佳替代品:Notepad++
    [No0000138]软件开发基础知识
    [No0000137]字符编码详解
    [No0000144]深入浅出图解C#堆与栈 C# Heap(ing) VS Stack(ing)理解堆与栈1/4
    [No0000136]6个重要的.NET概念:栈,堆,值类型,引用类型,装箱,拆箱
    [No0000135]程序员修炼之道 Tips
    phpstorm 调试时浏览器显示The requested resource / was not found on this server
    php注解
    phpStorm 配置PHP_CodeSniffer自动检查代码
    php
  • 原文地址:https://www.cnblogs.com/acm-bingzi/p/idea_name_x.html
Copyright © 2011-2022 走看看