A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Candy 高级黑马   /  2013-7-17 15:59  /  1023 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. 我通过读取XML里面的配置,调用配置信息,在遍历XML信息里调用shift()方法没反映,下面是代码可以帮我看看吗?
  2. 运行时没报错
  3. 读取XML代码:

  4. //获取回传XML配置信息
  5. public  List<FTPRead> getXml()
  6. {
  7. List<FTPRead> listftp = new ArrayList<FTPRead>();
  8. java.io.File file=new java.io.File("src//test.xml");      
  9.         //创建一个读取XML文件的对象      
  10.         SAXReader reader=new SAXReader();      
  11.         //创建一个文档对象      
  12.         Document document;

  13.         FTPRead read=new FTPRead();
  14. try
  15. {
  16. document = reader.read(file);
  17. //获取文件的根节点      
  18.         Element element=document.getRootElement();   
  19.         for(Iterator i=element.elementIterator("disk");i.hasNext();){   
  20.             //获取节点元素      
  21.             element=(Element)i.next();   
  22.       
  23.             String name=element.attributeValue("name");
  24.             read.setName(name);

  25.             //存储本地文件路径
  26.             String Localpath=element.elementText("Localpath");//取disk子元素capacity的内容   
  27.             read.setLocalpath(Localpath);
  28.             //上传FTP目录
  29.             String ftppath=element.elementText("ftppath");  
  30.          read.setFtppath(ftppath);
  31.           //回传FTP IP地址
  32.             String FTPIP=element.elementText("FTPIP");
  33.             read.setFTPIP(FTPIP);
  34.             //Ftp端口号
  35.             int port=Integer.parseInt(element.elementText("port"));
  36.             read.setPort(port);
  37.             
  38.             //FTP登录帐号
  39.             String username=element.elementText("username");
  40.             read.setUsername(username);
  41.             
  42.             //FTP登录密码
  43.             String password=element.elementText("password");
  44.             read.setPassword(password);
  45.             listftp.add(read);
  46.         }
  47. } catch (DocumentException e)
  48. {
  49. // TODO Auto-generated catch block
  50. e.printStackTrace();
  51. }
  52. return listftp;      
  53.         
  54. }

  55. 数据上传代码:
  56. //数据转移
  57. public static void shift(String name,String Localpath,String ftppath,String FTPIP, int port,String username,String password)
  58. {
  59. List listSpecies = TxTtoFtpaAtion.getTextFile(Localpath);
  60. System.out.println("上传始");
  61. for (int j = 0; j < listSpecies.size(); j++)
  62. {
  63.         //获取txt的文件路径名
  64.         String filepath ;
  65.         
  66.         //获取txt的文件名
  67.         String  filename;
  68.         
  69.         //获取.OK 的文件路径名
  70.         String filepathok;
  71.         
  72.         //获取.OK的文件名
  73.         
  74.         String filenameok;
  75. System.out.println("上传开始");
  76. boolean flag;
  77. // a=drg.substring(24);
  78. filepath = listSpecies.get(j).toString();
  79. System.out.println(filepath);
  80. filename = filepath
  81. .substring(Localpath.length() + 1);




  82. // 获取当前txt文件所对应的.ok文件路径
  83. filepathok = filepath.replace("txt", "ok");
  84. System.out.println(filepathok);
  85. // 获取当前txt文件所对应的.ok文件名

  86. filenameok = filepathok
  87. .substring(Localpath.length() + 1);
  88. if(filename.contains(".txt"))
  89. {
  90. //FTP上传方法
  91. flag=FileTool.upLoadFromProduction(FTPIP,port, username,
  92. password, ftppath,filename, filepath);
  93. //FTP上传方法
  94. if(flag)
  95. {
  96. flag=FileTool.upLoadFromProduction(FTPIP,port, username,
  97. password, ftppath,filenameok, filepathok);
  98. TxTtoFtpaAtion.copyFile(filepath, Localpath+"\\"+filename);
  99. TxTtoFtpaAtion.deleteFile(filepath);
  100. System.out.println(filepathok);
  101. System.out.println(filenameok);
  102. TxTtoFtpaAtion.copyFile(filepathok, Localpath+"\\"+filenameok);
  103. TxTtoFtpaAtion.deleteFile(filepathok);
  104. }
  105. }
  106. System.out.println("上传结束");
  107. }
  108. }

  109. //调用
  110. public static void main(String[] args) throws IOException
  111. {
  112. run();
  113. }

  114. private static void run()
  115. {
  116. // TODO Auto-generated method stub
  117. List<FTPRead> listftp= getXml();
  118. for (FTPRead ftpRead : listftp)
  119. {

  120. String name=ftpRead.getName();

  121. String Localpath=ftpRead.getLocalpath();

  122. String ftppath=ftpRead.getFtppath();

  123. String FTPIP=ftpRead.getFTPIP();

  124. int port=ftpRead.getPort();

  125. String username=ftpRead.getUsername();

  126. String password=ftpRead.getPassword();
  127. //读取本地文件路径目录下的.txt和.ok文件

  128. shift(name,Localpath,ftppath,FTPIP,port,username,password);//调用了这个方法没反映
  129.         System.out.println("开始");
  130.         
  131. }
  132.             
  133.            
  134. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
杨兴庭 + 1

查看全部评分

3 个回复

倒序浏览
{:soso_e179:}
回复 使用道具 举报
我去给你看下.. DOM4J, 我也是非常久没用了...
回复 使用道具 举报
楼主在了M我下, 我想看下你其他类完整的代码 给你做调试
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马