How to convert InputStream to FileInputStream

后端 未结 3 1428
悲&欢浪女
悲&欢浪女 2020-12-07 23:49

I have this line in my program :

InputStream Resource_InputStream=this.getClass().getClassLoader().getResourceAsStream(\"Resource_Name\");

3条回答
  •  粉色の甜心
    2020-12-08 00:36

    You need something like:

        URL resource = this.getClass().getResource("/path/to/resource.res");
        File is = null;
        try {
            is = new File(resource.toURI());
        } catch (URISyntaxException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            FileInputStream input = new FileInputStream(is);
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    

    But it will work only within your IDE, not in runnable JAR. I had same problem explained here.

提交回复
热议问题