Use Saxreader to read an XML file on an FTP server (original)

Source: Internet
Author: User
Tags ftp file

Depending on the project requirements, you need to monitor file changes on the FTP server and read the newly added files into the project system (no download is required).

Spring Configuration Timing task not much to say, it is important to note that now many projects are built through MAVEN, a lot of sub-projects, through the POM interdependence, the timing of the task of the configuration file needs to be placed in the Tomcat and other containers released by the project, and not put in the task of the sub-project inside, The class property of a bean can be read from the project dependencies into the class of other sub-projects, and the task class needs to have a construction method, involving the spring architecture of the bean knowledge, said a bit more ...

==================================================================

Get down to the chase-_-!

1. Several read methods in the Saxreader class

The files on the FTP server are ftpfile types, and the read (file) method is necessarily unavailable, as to whether the Ftpfile can be converted to file without much research; using the Read (URL) method, URL fill in the file corresponding to the FTP address times wrong (not available user name password), because this is not used ftpclient to read the ftp file, no login server, no permissions is inevitable, as to how to use Saxreader login FTP server to read Ftpfile, not too much research. These two aspects have time to look back again later.

The Read (Imputstream) method is feasible, whether it seems to be used or not.

    /*** Parse XML file, read the information in each tag in XML *@paramfpath ftp file, for example: A.xml *@paramename XML tags, for example: "//sciencereading_book:id" *@returncontent in the XML tag*/     Publicstring Parsexml (Ftpfile Fpath, String ename) {string Rtn= ""; Document Document=NULL; InputStream ins=NULL; Try{saxreader Saxreader=NewSaxreader (); INS= This. Ftp.retrievefilestream (Fpath.getname ()); Document=saxreader.read (INS); List list_1=document.selectnodes (ename);  for(Iterator iter =list_1.iterator (); Iter.hasnext ();) {element element=(Element) iter.next (); RTN=Element.gettext ();        } ftp.getreply (); } Catch(IOException e) {e.printstacktrace (); } Catch(documentexception e) {e.printstacktrace (); } finally {            if(INS! =NULL){                Try{ins.close (); } Catch(IOException e) {e.printstacktrace (); }            }        }        returnRtn; }}

Special Note:ftp.getreply (); Must not forget, the next 226 consumption, if not written, the next time This.ftp.retrieveFileStream () The returned InputStream object will always be null!!!

Log as follows:

If you do not write, then only RETR b97870302061380003600.xml \ n Port command successful. (no file is read into the input stream)

Use Saxreader to read an XML file on an FTP server (original)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.