有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java文件存在于目录中,但仍在获取。linux中的FileNotFoundException在linux中执行junit测试用例,但在windows中执行它的fiine

我的一个测试用例失败,出现了“java.io.FileNotFoundException:/home/utility/abc.xsd(没有这样的文件或目录)”异常,但该文件存在于该路径中,甚至该文件对所有级别都有读取权限(-rw-r--r--)

但同样的方法在windows中也可以正常工作

public void test1() {
   URL schUrl = getClass().getClassLoader().getResource("/home/utility/abc.xsd"); //At this line error is occuring
}

我试着加上 file.read() , file.exist()并且它的显示都是错误的

java.io.FileNotFoundException: /home/utility/abc.xsd (No such file or directory)
at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:146)
        at java.io.FileInputStream.<init>(FileInputStream.java:101)
        at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
        at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
        at java.net.URL.openStream(URL.java:1048)
        at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
        at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
        at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
        at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:392)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:274)
        at com.ares.ocg.util.xml.sax.SchemaImpl.init(SchemaImpl.java:258)
        at com.ares.ocg.util.xml.schema.SchemaProvider.getSchema(SchemaProvider.java:144)
        at com.ares.ocg.util.xml.schema.TestSchema.testSchemaElement(TestSchema.java:57)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at junit.framework.TestCase.runTest(TestCase.java:168)
        at junit.framework.TestCase.runBare(TestCase.java:134)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:124)
        at junit.framework.TestSuite.runTest(TestSuite.java:243)
        at junit.framework.TestSuite.run(TestSuite.java:238)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)

请建议我如何解决这个问题


共 (0) 个答案