Android 用文档生成器解析XML
在我的应用程序中,我试图从FTP服务器下载一个文件,并将检索到的inputstream转换为文档对象,这样我就能够解析XML了。 我以前这样做过,效果很好,但由于一些奇怪的原因,对文档对象的转换一直在运行,并且不会完成。考虑到我没有修改任何代码,这真的很奇怪。这是我的密码:Android 用文档生成器解析XML,android,xml,inputstream,document,Android,Xml,Inputstream,Document,在我的应用程序中,我试图从FTP服务器下载一个文件,并将检索到的inputstream转换为文档对象,这样我就能够解析XML了。 我以前这样做过,效果很好,但由于一些奇怪的原因,对文档对象的转换一直在运行,并且不会完成。考虑到我没有修改任何代码,这真的很奇怪。这是我的密码: public Document download(Document document){ Log.d("Download", "Attempt to download file");
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文件来解决我的问题(比如较小的文件),但我的应用程序在这个过程中一直失败。
有人能告诉我发生了什么事吗?我检查了我的FTP服务器,但它运行不好。 所以我重新启动了我的笔记本电脑,并试图再次运行它。 我的应用程序目前运行良好,这不是代码问题,而是服务器问题