English 中文(简体)
Kotlin - 档案并非例外: 档案确实存在。
原标题:Kotlin - File Not Found Exception: File does exist though

我在试图将XML档案中的内容纳入我的科特林申请时,正在讨论以下问题:

java.io.FileNotFoundException: /src/main/res/locations.xml: open failed: ENOENT (No such file or directory)

下面是处理文件装载的法典:

fun parseToObject() {
    val thread = Thread(Runnable {
        try {
            val xml = File("src/main/res/locations.xml")
            val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xml)
            println("Root Node: " + doc.documentElement.nodeName)
        } catch (e: Exception) {
            print(e.message)
        }
    })
    thread.start()
}

任何人都知道我会做什么错误? 我尝试采用完全的道路,缩短道路,似乎不喜欢其中的任何一条。

问题回答

你们只能把项目档案作为文件,作为投入。 并且你一定能够查阅<代码>res中的具体档案。 页: 1 否则,由于优化,在安装的配料中甚至可能不存在。

您可在<条码>中填写。 页: 1 你可以把档案内容作为投入文件(而不是直接作为文件)。

使用原材料:

val doc = Resources.openRawResource(R.raw.locations).use { xmlInputStream ->
    DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlInputStream)
}
println("Root Node: " + doc.documentElement.nodeName)

使用资产:

val doc = context.assets.open("locations.xml").use { xmlInputStream ->
    DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlInputStream)
}
println("Root Node: " + doc.documentElement.nodeName)

原材料和混合物与资产:

原材料有身份证,可参考其他资源XML文件。 资产只能通过Sting文档名称查询,但可在asset内编成子。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签