在线读取文件,编辑文件,COPY文件的工具代码

我们在运维过程中,经常需要做一些配置,如果有一个工具可以帮你在线修改后台配置文件
读取配置文件内容,同步配置文件到所有机器,是跟我们带来极大的便利性的。

如下为我做这个工具的思路:
在线配置文件的页面用easyui实现

配置文件工具单独在一个页签,页面上显示配置文件名称,配置文件功能描述,配置文件内容
1、鼠标悬浮在配置文件内容时以悬浮的提示方式显示文本内容
2、FileData字段带超链接,点击超链接时新开一个窗口,该窗口可以查看和修改文件内容
3、新窗口有两个按钮,保存和取消
4、点击保存时将页面的内容写入到生产机对应的配置文件
5、当文件发生更改时,将文件同步copy到另外两套服务器上
6、写入文件时指定文件格式为UTF-8,读取配置文件内容时也用UTF-8
7、如果当前页面编辑的是xml文件,则需要对特殊字符做转译
8、如果是properties文件,需要对空格的特殊处理
9、读取配置文件写一个热加载的公共类,支持各种类型的文件

我会在系统上线前,运行代码扫描指定目录下我们可查看到的文件类型文件,把所有文件写到files.txt文件
文件内容为:文件名称,功能描述,文件路径

然后工具页面从files.txt读取这些内容,显示到页面上

用户在点击查看文件内容时,我们通过文件路径去获取文件内容单独显示

/* bcwti
 *
 * Copyright (c) 2010 Parametric Technology Corporation (PTC). All Rights Reserved.
 *
 * This software is the confidential and proprietary information of PTC
 * and is subject to the terms of a software license agreement. You shall
 * not disclose such confidential information and shall use it only in accordance
 * with the terms of the license agreement.
 *
 * ecwti
 */
package ext.restlet;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.json.JSONException;

import wt.util.WTProperties;

/**
 * This processor initializes and saves Promotion Requests with the attribute
 * values entered in the Promotion Request wizard.
 * 
 * <BR>
 * <BR>
 * <B>Supported API: </B>true <BR>
 * <BR>
 * <B>Extendable: </B>true
 * 
 */
public class FileSaveAndCopyTools {
   
    private static List<String> fileFiter = Arrays.asList(".txt", ".properties", ".xls", ".xlsx", ".xml", ".xconf",
            ".vm");

    public static void main(String[] args) throws JSONException, IOException {
        String wthome = "D:\\ptc\\Windchill_10.0\\Windchill";
//               (String) (WTProperties.getLocalProperties()).getProperty("wt.home", "") + File.separator;
        // 测试初始化全量配置文件到files.txt文件
//       String filesPath = wthome + File.separator +"codebase"+ File.separator+"ext";
//       initFilesTxt(filesPath);

        // 测试读取指定路径的文件内容
//      String filesPath = wthome + File.separator +"codebase"+ File.separator+"wt.properties";
//      System.out.println(readTxt(filesPath));

        // 测试从files.txt读取系统中全量的业务配置文件
//      List<Map<String, String>> bussnessConfigFile  = getPlmBussnessConfigFiles4FileTxt();
//      System.out.println(bussnessConfigFile.toString());

        // 根据文件路径和页面传递的内容修改文件
//       filesPath = "D:\\ptc\\Windchill_10.0\\Windchill\\codebase\\files.txt";
//       String fileTxt = "测试写文件";
//       boolean updateState = saveBussnessFile(filesPath, fileTxt);
//       System.out.println(updateState);

        // 页面编辑配置文件的业务描述,点击保存时将数据更新到files.txt文件
//       String targetFilePath = "D:\\ptc\\Windchill_10.0\\Windchill\\codebase\\ext\\util\\mail\\footer.txt";
//       boolean modifyState = saveFilesTxtContent(targetFilePath, "通用邮件配置文件模板");
//       System.out.println("修改某个配置文件的描述,是否成功="+modifyState);

    }

    /**
     * 
     * 使用文件通道的方式复制文件
     * @param s
     *          源文件
     * @param t
     *          复制到的新文件
     */
    public static void fileChann
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值