/**
     * 插入文件第一行(推荐)
     *
     * @param content 要插入的内容
     * @throws IOException
     */
    public static void insertAtBeginning(String filePath, String content) throws IOException {
        File file = new File(filePath);
        if (!file.exists()) {
            boolean newFile = file.createNewFile();
        }
        try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
            byte[] originalContent = new byte[(int) raf.length()];
            raf.read(originalContent);
            raf.seek(0);
            raf.write((content + "\n").getBytes());
            raf.write(originalContent);
        }
    }

    /**
     * 插入文件第一行 推荐使用 insertAtBeginning
     */
    @Deprecated
    public static void writeFileToFirstLine(String filePath, String content) {
        File file = new File(filePath);
        RandomAccessFile randomAccessFile = null;
        try {
            // 读取原始文件内容
            byte[] originalContent = new byte[(int) file.length()];
            randomAccessFile = new RandomAccessFile(file, "rw");
            randomAccessFile.readFully(originalContent);

            // 将文件指针移到开头
            randomAccessFile.seek(0);

            // 写入新内容
            randomAccessFile.write(content.getBytes());

            // 写入原始内容
            randomAccessFile.write(originalContent);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (randomAccessFile != null) {
                try {
                    randomAccessFile.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }