在java中打开文件给出异常

时间:2012-02-16 06:29:00

标签: java exception netbeans jpcap

我通过filenamechooser获取文件名并将其发送给我所需的处理方法,但问题是它不接受文件名。我正在使用JPcap打开文件。当我硬编码时,它给出了我完美的结果,但当我发送文件名时,它给了我异常。这是我的代码

     JpcapCaptor captor = JpcapCaptor.openFile("E:\\10.pcap");

我接受了这个文件的打印声明,它给了我这个

      System.out.println("E:\\10.pcap");
控制台上的

我得到了这个

E:\ 10.pcap

但是当我从我的GUI发送这个文件名到这个openfile函数时,它给了我这个例外,虽然当我拿这个文件名的打印语句时它也是相同的E:\ 10.pcap

  SEVERE: null
 java.io.IOException: E:\10.pcap
: Invalid argument
at jpcap.JpcapCaptor.openFile(JpcapCaptor.java:93)
at dpi.Functions.PortBasedAnalysis(Functions.java:52)
at dpi.GraphicalInterface.jButton1MouseClicked(GraphicalInterface.java:104)
at dpi.GraphicalInterface.access$000(GraphicalInterface.java:25)
at dpi.GraphicalInterface$1.mouseClicked(GraphicalInterface.java:49)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
at java.awt.Component.processMouseEvent(Component.java:6041)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3995)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at      java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

1 个答案:

答案 0 :(得分:0)

尝试在File Chooser返回的Path上使用trim()函数