繁体   English   中英

如何在ftp服务器中只读取十二个文件?

[英]How to read only twelve file in ftp server?

如何只读取十二个文件,因为我只读取 ftp 服务器中的所有文件,并且每 4 分钟添加一个新文件。

感谢您的帮助,我是 API 编程的初学者:)

if(files.length>12){ //amount list of files
                    for (FTPFile file : files) {
                        try {
                            System.out.println("                        "
                                    + file.getName());
                            fileName = "/AGIN/" + dir + "/" + file.getName();
                            iStream = ftpClient.retrieveFileStream(fileName);
                            br = new BufferedReader(new InputStreamReader(
                                    iStream));
                            sb = new StringBuffer();
                            while ((line = br.readLine()) != null) {
                                sb.append(line);
                            }
                            String xmlStr = "<betRecordList>" + sb.toString()
                                    + "</betRecordList>";
                            jaxbContext = JAXBContext
                                    .newInstance(BetRecordList.class);
                            jaxbUnmarshaller = jaxbContext.createUnmarshaller();
                            ByteArrayInputStream bis = new ByteArrayInputStream(
                                    xmlStr.getBytes());
                            StreamSource ss = new StreamSource(bis);
                            returnlist = jaxbUnmarshaller.unmarshal(ss,
                                    returnClazz);
                            ret = (BetRecordList) returnlist.getValue();
                            System.out.println("" + ret.getRecord()); // the xml files read from the ftp server

                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            try {
                                if (iStream != null) {
                                    iStream.close();
                                    iStream = null;
                                }
                                if (bInf != null) {
                                    bInf.close();
                                    bInf = null;
                                }

                                boolean isComplete = ftpClient
                                        .completePendingCommand();
                                System.out.println("isComplete::" + isComplete);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                    }
                }

                boolean logout = ftpClient.logout();
                if (logout) {
                    System.out.println("Connection close");
                }
            } else {
                System.out.println("Connection fail");
            }

        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (iStream != null) {
                    iStream.close();
                }
                if (bInf != null) {
                    bInf.close();
                }
                ftpClient.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return ret.getRecord();
    }
for (int i = 0; i < files.length && i < 12; ++i) {
    FTPFile file = files[i];
    ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM