我正在尝试用java读取ofx文件。 但我得到以下错误:Unhandled exception type FileNotFoundException
(第二行)。我正在使用OFx4j。你能给我一些关于那个的提示吗?用java解析Ofx文件
这是迄今为止我所编写的代码:
String filename=new String("C:\\file.ofx");
FileInputStream file = new FileInputStream(filename);
NanoXMLOFXReader nano = new NanoXMLOFXReader();
try
{
nano.parse(stream);
System.out.println("woooo It workssss!!!!");
}
catch (OFXParseException e)
{
}
感谢您的意见,我做了一些改变:
String FILE_TO_READ = "C:\\file.ofx";
try
{
FileInputStream file = new FileInputStream(FILE_TO_READ);
NanoXMLOFXReader nano = new NanoXMLOFXReader();
nano.parse(file);
System.out.println("woooo It workssss!!!!");
}
catch (OFXParseException e)
{
System.out.println("Message : "+e.getMessage());
}
catch (Exception e1)
{
System.out.println("Other Message : "+e1.getMessage());
}
但现在我得到这样的:
异常在OfxTest。OfxTest.afficherFichier(OfxTest.java:31) 在线程“main”java.lang.NoClassDefFoundError:net/n3/nanoxml/XMLParseException 。 main(OfxTest.java:20) 引发:java.lang.ClassNotFoundException:net.n3.nanoxml.XMLParseException at java.net.URLClassLoader $ 1.run(未知源) at java.security.AccessController.doPrivileged(Native法) 在java.net.URLClassLoader.findClass(来源不明) 在java.lang.ClassLoader.loadClass(来源不明) 在sun.misc.Launcher $ AppClassLoader.loadClass(来源不明) 在java.lang.ClassLoader中.loadClass(未知源) ... 2更多
我想弄明白。我相信它找不到XMLParseException。但我不确定。
您正在打开一个流,但没有检查异常。 – doNotCheckMyBlog
不要写'new String(“C:\\ file.ofx”)',只需写'String filename =“C:\\ file.ofx”;'没有理由显式创建一个新的'String'对象来自文字字符串。 – Jesper
注意到@Jesper,在阅读他/她的异常之后,我直接跳转到输入流代码:)。 – doNotCheckMyBlog