New to Scala and having problems reading an XML file in a Scala worksheet. So far I have:
- downloaded the Scala IDE (for Windows) and unzipped it to my
C:\drive - created a Scala project with the following file path:
C:\eclipse\workspace\xml_data - created the
xmlfile...\xml_data\music.xmlusing the following data created a package
sample_dataand create the following object (with file path:...\xml_data\src\sample_data\SampleData.scala):package sample_data import scala.xml.XML object SampleData { val data = XML.loadFile("music.xml") } object PrintSampleData extends Application { println(SampleData.data) }
This runs OK, however, when I create the Scala worksheet test_sample_data.sc:
import sample_data.SampleData
object test {
println(SampleData.data)
}
I get a java.lang.ExceptionInInitializerError which includes: Caused by: java.io.FileNotFoundException: music.xml (The system cannot find the file specified).
The workspace is C:\eclipse\workspace. Any help or insight much appreciated. Cheers!
UPDATE:
Following aepurniet's advice, I ran new java.io.File(".").getAbsolutePath() and got the following respectively:
SampleData.scala:C:\eclipse\workspace\xml_data\.test_sample_data.sc:C:\eclipse\.
So this is what is causing the problem. Does anyone know why this occurs? Absolute file paths resolve the problem. Is this the best solution?