How do I reference a resource in Java?

前端 未结 2 1499
名媛妹妹
名媛妹妹 2020-12-14 22:07

I need to read a file in my code. It physically resides here:

C:\\eclipseWorkspace\\ProjectA\\src\\com\\company\\somePackage\\MyFile.txt

I

2条回答
  •  借酒劲吻你
    2020-12-14 22:33

    If I have placed i file in a jar file, it only worked if and only if I used

    ...getResourceAsStream("com/company/somePackage/MyFile.txt")
    

    If I used a File object it never worked. I got also the FileNotFound exception. Now, I stay with the InputStream object.

提交回复
热议问题