Tôi đang sử dụng org.apache.commons.net.ftp.FTPCẩn và nhìn thấy hành vi đó, cũng ... phức tạp.Sự cố với lớp FTPClient trong java
Phương pháp bên dưới dự định đi qua danh sách FTPFile, đọc chúng và sau đó thực hiện điều gì đó với nội dung. Đó là tất cả làm việc. Những gì không (thực sự) làm việc là các đối tượng FTPClient làm như sau ...
1) Properly retrieves and stores the FIRST file in the list
2) List item evaluates to NULL for x number of successive iterations of the loop (x varies on successive attempts
3) manages to retrieve exactly 1 more file in the list
4) reports that it is null for exactly 1 more file in the list
5) hangs indefinitely, reporting no further activity.
public static String mergeXMLFiles(List<FTPFile> files, String rootElementNodeName, FTPClient ftp){
String ret = null;
String fileAsString = null;
//InputStream inStream;
int c;
if(files == null || rootElementNodeName == null)
return null;
try {
System.out.println("GETTING " + files.size() + " files");
for (FTPFile file : files) {
fileAsString = "";
InputStream inStream = ftp.retrieveFileStream(file.getName());
if(inStream == null){
System.out.println("FtpUtil.mergeXMLFiles() couldn't initialize inStream for file:" + file.getName());
continue;//THIS IS THE PART THAT I SEE FOR files [1 - arbitrary number (usually around 20)] and then 1 more time for [x + 2] after [x + 1] passes successfully.
}
while((c = inStream.read()) != -1){
fileAsString += Character.valueOf((char)c);
}
inStream.close();
System.out.println("FILE:" + file.getName() + "\n" + fileAsString);
}
} catch (Exception e) {
System.out.println("FtpUtil.mergeXMLFiles() failed:" + e);
}
return ret;
}
có ai nhìn thấy bất cứ điều gì như thế này? Tôi mới tham gia FTPClient, tôi có làm gì sai với nó không?
bạn có thể chỉnh sửa bài viết của bạn nên thay vì sử dụng giao diện mã cho mục danh sách của bạn, bạn thay vì sử dụng shortcodes cung cấp cho các hạng mục danh sách? Làm cho nó dễ đọc hơn theo cách đó :) – Kezzer