使用upLoadFromProduction()读取本地文件夹的内容进行上传目标,打包好的程序异常关闭,有异常信息么?

解决方案 »

  1.   

    这个是一个方法源码:
    File directory = new File("FTPUpload.xml");
    if (!directory.exists())
    {
    try
    {
    XMLGenerate j2x = new XMLGenerate();
    System.out.println("生成 mxl 文件...");
    j2x.BuildXMLDoc();
    } catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    // TODO Auto-generated method stub
    java.io.File file = new java.io.File(directory.getCanonicalPath()); // 创建一个读取XML文件的对象
    SAXReader reader = new SAXReader();
    // 创建一个文档对象
    Document document; FTPRead read = new FTPRead();
    document = reader.read(file);
    // 获取文件的根节点
    Element element = document.getRootElement();
    for (Iterator i = element.elementIterator("disk"); i.hasNext();)
    {
    // 获取节点元素
    element = (Element) i.next(); String name = element.attributeValue("name"); // 存储本地文件路径
    String Localpath = element.elementText("Localpath"); // 上传FTP目录
    String ftppath = element.elementText("ftppath"); // 回传FTP IP地址
    String FTPIP = element.elementText("FTPIP"); // Ftp端口号
    int port = Integer.parseInt(element.elementText("port")); // FTP登录帐号
    String username = element.elementText("username"); // FTP登录密码
    String password = element.elementText("password"); // FTP回传数据报错反馈文件夹
    String ftperrors = element.elementText("ftperrors"); // 本地存储FTP回传报错目录
    String ftpLocal = element.elementText("ftpLocal"); // 上传报错信息
    String ftpLocalerror = element.elementText("ftpLocalerror"); // 文件备份路径
    String Localfilegx = element.elementText("Localfilegx"); // 文件备份路径
    String Localfiletx = element.elementText("Localfiletx");

    //FtpDownFiles fd = new FtpDownFiles();

    //fd.connectServer(FTPIP, username, password);

    //fd.ftpDownFiles(ftperrors, ftpLocal); if (!(new File(Localpath).isDirectory()))
    {
    new File(Localpath).mkdir();
    }
    if (!(new File(ftpLocal).isDirectory()))
    {
    new File(ftpLocal).mkdir();
    }
    if (!(new File(Localfilegx).isDirectory()))
    {
    new File(Localfilegx).mkdir();
    }
    if (!(new File(Localfiletx).isDirectory()))
    {
    new File(Localfiletx).mkdir();
    }
    if (!(new File(ftpLocalerror).isDirectory()))
    {
    new File(ftpLocalerror).mkdir();
    }
    // 获取配置目录下的.txt和.OK文件
    List list = getTextFile(Localpath); TxTtoFtpaAtion log = new TxTtoFtpaAtion();
    if(list.size()!=0)
    {
    log.log4j(name + ":准备开始上传FTP");
    for (int j = 0; j < list.size(); j++)
    {
    if(j==list.size()-1)
    {
    Timer timer1 = new Timer();
    MonitorTimerTask monitor=new MonitorTimerTask();
    timer1.scheduleAtFixedRate(monitor, 0, 5*60*1000L);

    }
    //System.out.println(list.get(j));
    // 获取txt的文件路径名
    String filepath; // 获取txt的文件名
    String filename; // 获取的文件路径名
    String filepathok; // 获取的文件名 String filenameok;

    boolean flag;

    filepath = list.get(j).toString();

    filename = filepath.substring(Localpath.length() + 1); // 获取当前txt文件所对应的.ok文件路径
    filepathok = filepath.replace("txt", "ok"); // 获取当前txt文件所对应的.ok文件名
    filenameok = filepathok.substring(Localpath.length() + 1); // 回传数据类别
    String type = null; // 文件备份路径
    String Localfile;

    // 区别种类name属性
    String Category = ".txt";
    String Category1 = ".txt";
    String Category2 = ".txt";

    if (filename.contains(Constant.LOGISTICS))
    {
    type = name + "信息上传:";
    } else if (filename.contains(Constant.SUCCESS))
    {
    type = name + "信息上传:";
    } else if (filename.contains(Constant.STAMPP))
    {
    type = "信息上传:";
    } else if (filename.contains(Constant.STAMPV))
    {
    type = "信息上传:";
    } else if (filename.contains(Constant.LOGISTICS))
    {
    type = name + "物流信息上传:";
    } else if (filename.contains(Constant.SUCCESS))
    {
    type = name + "保单信息上传:";
    } else if (filename.contains(Constant.REPORT))
    {
    type = "清单生产信息上传:";
    } if ("...".equals(name.trim()))
    {
    Category = Constant.SUCCESS;
    Category1 = Constant.LOGISTICS;
    Category2 = Constant.REPORT;
    Localfile = Localfilegx;
    } else if ("..".equals(name.trim()))
    {
    Category = Constant.STAMPP;
    Category1 = Constant.STAMPV;
    Category2 = Constant.STAMPP;
    Localfile = Localfilegx; } else
    {
    Category = ".txt";
    Category1 = ".txt";
    Category2 = ".txt";
    Localfile = Localfiletx;
    }
    if (filename.contains(".txt")
    && (filename.contains(Category)
    || filename.contains(Category1) || filename
    .contains(Category2)))
    {
    // 获取当前读取的txt中有多少条记录
    int txtRecord = TxTtoFtpaAtion.FilenumberTxt(filepath);

    // System.out.println(txtRecord);
    // 获取当前txt中应导出记录数
    int txtnumber = TxTtoFtpaAtion.GetQuantity(filename);

    if (filename.contains(Constant.STAMPP)
    || filename.contains(Constant.STAMPV)
    || filename.contains(Constant.LOGISTICS)
    || filename.contains(Constant.SUCCESS))
    {
    if (txtRecord == txtnumber)
    {

    // FTP上传方法
    flag = FileTool.upLoadFromProduction(FTPIP,
    port, username, password, ftppath,
    filename, filepath);
    // 判断文件是否存在,不存在就创建
    java.io.File myFilePath = new java.io.File(
    filepathok);
    if (!myFilePath.exists())
    {
    try
    {
    myFilePath.createNewFile();
    } catch (IOException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } } // FTP上传方法
    if (flag)
    {
    log.log4j(type + filename + "上传成功,共上传"
    + txtnumber + "条记录");
    flag = FileTool.upLoadFromProduction(FTPIP,
    port, username, password, ftppath,
    filenameok, filepathok);

    TxTtoFtpaAtion.copyFile(filepath, Localfile
    + "\\" + filename);

    log.log4j(type + filename + "备份成功");
    TxTtoFtpaAtion.deleteFile(filepath);
    log.log4j(type + filename + "原始数据删除成功");

    System.out.println(type + filepath + ":文件处理成功"); if (flag)
    {
    log.log4j(type + filepathok
    + "效验文件上传成功");

    TxTtoFtpaAtion.copyFile(filepathok,
    Localfile + "\\" + filenameok);

    log.log4j(type + filepathok + "备份成功");


    TxTtoFtpaAtion.deleteFile(filepathok);

    log.log4j(type + filepathok + "备份成功");

    System.out.println(type + filepathok + ":文件处理成功");

    }
    } else
    {
    log.log4j("FTP上传失败,请检查网络或配置是否正确");
    } } else
    {
    log.log4j(type + filename
    + "上传失败,文件内容数据与回传数据已一致,可能数据丢失,请排查");

    TxTtoFtpaAtion.copyFile(filepath, ftpLocalerror
    + "\\" + filename);

    TxTtoFtpaAtion.deleteFile(filepath);

    TxTtoFtpaAtion.copyFile(filepathok, ftpLocal
    + "\\" + filenameok);

    TxTtoFtpaAtion.deleteFile(filepathok); log.log4j(type + filename + "文件已移至错误目录");

    log.log4j(type + filename + "文件已删除");

    log.log4j(type + filenameok + "文件已移至错误目录");

    log.log4j(type + filenameok + "文件已删除");

    System.out.println(type + filename +"文件异常,请排查处理,数据不一致");
    } } else
    {
    // FTP上传方法
    flag = FileTool.upLoadFromProduction(FTPIP, port,
    username, password, ftppath, filename,
    filepath);

    // FTP上传方法
    if (flag)
    {
    flag = FileTool.upLoadFromProduction(FTPIP,
    port, username, password, ftppath,
    filenameok, filepathok);

    TxTtoFtpaAtion.copyFile(filepath, Localfile
    + "\\" + filename);

    TxTtoFtpaAtion.deleteFile(filepath);
    TxTtoFtpaAtion.copyFile(filepathok, Localfile
    + "\\" + filenameok);

    TxTtoFtpaAtion.deleteFile(filepathok);

    log.log4j(filename + "上传成功");

    log.log4j(filepathok + "上传成功");
    System.out.println(filepath+"文件处理成功");
    System.out.println(filepathok+"文件处理成功");
    } else
    {
    log.log4j("网络异常,请协助处理");
    }
    }
    }
    }
    }
    }
    } catch (DocumentException e1)
    {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    } catch (IOException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (Exception e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
      

  2.   

    是不是操作的文件过大使用"jconsole"这个JDK自带工具,监控一下在JAVA安装目录的bin目录下.
    GUI工具,你应该看了就明白了.
      

  3.   

    给了你方法了,后面还有几个选项卡.你如果是内存不够,你应该看一下到底是什么吃了内存.而且你这个图现在也没有问题,线程不多,内存占用正常...CPU也没怎么用.