• 关于多个的线程操作文件 文件句柄(java中得文件流)


    //审批基本信息
    public static Map<String, String> writeBasicToMap(Class gcprojcheckupClas,String fileDirPath,Map<String, Object> map) throws Exception{
    Document doc = DocumentHelper.createDocument();
    //增加根节点
    Element root = doc.addElement("GCData");
    //获取类名
    String className= StrUtils.getClassnameByPackage(gcprojcheckupClas.getName());
    //增加子元素
    Element GCProjCheckup = root.addElement(className);//不需要小写

    //增加结点
    Field [] gcprojcheckupFields = gcprojcheckupClas.getDeclaredFields();
    for (int i = 0; i < gcprojcheckupFields.length; i++) {
    System.out.println(gcprojcheckupFields[i].getName());
    String key = gcprojcheckupFields[i].getName();
    Element element = GCProjCheckup.addElement(key);//标签和属性命名一致
    element.setText(map.get(key.toLowerCase())==null ? "": (String)map.get(key.toLowerCase()));

    }
    // //特殊处理LeaderGXUniCode_OrganOfLeader
    // Element element = root.addElement("LeaderGXUniCode_OrganOfLeader");
    // element.addText(map.get("LGOL")==null? "" :(String)map.get("LGOL"));


    //实例化输出格式对象
    OutputFormat format = OutputFormat.createPrettyPrint();
    //设置输出编码
    format.setEncoding("UTF-8");
    //创建需要写入的File对象
    String fileName = NameUtils.getFileName(map.get("unitid")==null?"":map.get("unitid").toString(),map.get("unitname")==null?"":map.get("unitname").toString(), StrUtils.getClassnameByPackage(gcprojcheckupClas.getName()));
    String finalPath=CommonPath.INROOTPATH+fileDirPath + File.separator+ fileName+".xml";
    System.out.println(finalPath);
    File file = new File(finalPath);
    //生成XMLWriter对象,构造函数中的参数为需要输出的文件流和格式
    FileOutputStream fileoutputstream = new FileOutputStream(file);
    XMLWriter writer = new XMLWriter(fileoutputstream, format);
    //开始写入,write方法中包含上面创建的Document对象
    writer.write(doc);
    if(writer!=null) writer.close();
    if(fileoutputstream!=null) fileoutputstream.close();

    Map<String, String> backMap = new HashMap<String, String>();
    backMap.put("filename", fileName);
    FileInputStream inputStream = new FileInputStream(finalPath);
    String md5 = DigestUtils.md5Hex(inputStream);
    if(inputStream!=null) {inputStream.close();};
    backMap.put("md5",md5);
    return backMap;
    }

  • 相关阅读:
    定时器实现点击重新发送信息倒计时显示
    新浪微博5s钟后跳转页面
    时钟制作代码
    判断线段相交
    POJ1265:Area(多边形面积公式+pick公式) 好题
    ACM零散知识
    POJ2318:TOYS(叉积判断点和线段的关系+二分)&&POJ2398Toy Storage
    计算几何初步认识
    UVA10026:Shoemaker's Problem(贪心)
    UVA10020:Minimal coverage(最小区间覆盖)
  • 原文地址:https://www.cnblogs.com/zshboke-2015/p/4988389.html
Copyright © 2020-2023  润新知