在我的应用程序中,我正在尝试从FTP服务器下载文件并将检索到的输入流转换为Document对象,因此我将能够解析XML。 我以前做过这个并且工作得很好,但由于一些奇怪的原因,转换为Document对象继续运行并且无法完成。考虑到我没有修改任何代码,这真的很奇怪。这是我的代码:
public Document download(Document document){
Log.d("Download", "Attempt to download file");
String remoteFile;
InputStream inputStream;
try{
String rootDirectory = ftpClient.printWorkingDirectory();
FTPFile[] locatedFiles = ftpClient.listFiles(rootDirectory);
int x = locatedFiles.length;
if(x != 0){
remoteFile = locatedFiles[0].getName();
Log.d("Download", "File detected");
try{
ftpClient.setBufferSize(1024*1024);
inputStream = ftpClient.retrieveFileStream(remoteFile);
Log.d("Download", "File retrieved");
try{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Log.d("Download", "Builder object made for converting file");
try{
document = builder.parse(inputStream); // This is the piece of code which keeps running and never finishes
Log.d("Download", "File converted");
try{
inputStream.close();
User.getInstance().setDownloadedDay(User.getInstance().getCurrentDay());
User.getInstance().setDownloadedMonth(User.getInstance().getCurrentMonth());
User.getInstance().setDownloadedYear(User.getInstance().getCurrentYear());
Log.d("Download", "Closed input stream");
}catch(IOException e){
Log.e("Download", e.getMessage());
}
}catch(SAXException e){
Log.e("Download", e.getMessage());
}catch(IOException e){
Log.e("Download", e.getMessage());
}
}catch(ParserConfigurationException e){
Log.e("Download", e.getMessage());
}
}catch(IOException e){
Log.e("Download", e.getMessage());
}
}else{
Log.w("Download", "No file detected");
}
}catch(IOException e){
Log.e("Download", e.getMessage());
}
return document;
}
其中显示“已转换文件”的日志永远不会弹出,这表示转换仍在进行中。我已经尝试了多个XML文件来解决我的问题(比如小问题),但是我的应用程序一直在使这个过程失败。 有人能告诉我发生了什么事吗?
答案 0 :(得分:0)
我检查了我的FTP服务器,但运行状况不佳。 所以我重新启动我的笔记本电脑,并试图再次运行它。 我的应用程序目前运行正常,它不是代码,这是服务器的问题。