मैं कोशिश कर रहा हूँ पढ़ने के लिए एक फ़ाइल "my_data.txt" बैठते हैं कि में मेरे /src/test/resources/data
फ़ोल्डर.
––– src
–– main
–– test
––– resources
––– data
––– my_data.txt
मैं कोड के निम्नलिखित टुकड़ा करने के लिए है कि क्या:
val filename = getClass.getResource("/src/test/resources/data/my_data.txt").getPath
जब मैं यह संकलन, संकलन अच्छी तरह से चला गया, तथापि, जब मैं परीक्षण चलाने में ducker, मैं निम्नलिखित त्रुटि संदेश:
java.lang.NullPointerException
at (xxxx.scala:128)
at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.FunSpecLike$$anon$1.apply(FunSpecLike.scala:454)
at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
at org.scalatest.FunSpec.withFixture(FunSpec.scala:1630)
at org.scalatest.FunSpecLike.invokeWithFixture$1(FunSpecLike.scala:452)
at org.scalatest.FunSpecLike.$anonfun$runTest$1(FunSpecLike.scala:464)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
at org.scalatest.FunSpecLike.runTest(FunSpecLike.scala:464)
at org.scalatest.FunSpecLike.runTest$(FunSpecLike.scala:446)
When I try to print the path that I am reading from I got `null` as an output.
एक और प्रयास
के अलावा ऊपर, मैं करने की कोशिश की निम्न कोड:
val ss = scala.io.Source.fromResource("/src/test/resources/data/my_data.txt")
ClassLoader.getSystemResource("/src/test/resources/data/my_data.txt").getPath
इसके अलावा, मैं जोड़ा गया src/test/resources/data
करने के लिए संसाधनों में POM
फ़ाइल
अंत में
के रूप में यह उल्लेख किया है, मैं जाँच की, तो मैं है .txt
में शामिल संकलक ( मैं का उपयोग कर रहा हूँ MAC
)