无法链接已部署的Java程序中的属性文件 [英] Not able to link properties file in deployed java program

查看:91
本文介绍了无法链接已部署的Java程序中的属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成项目,但一切正常,但是当我将其部署到.jar时,它没有显示图像, 所以我在网上搜索并找到了最初使用此解决方案的方法

I just finished my project everything is working fine but when i deployed it to .jar it was not showing images, so i searched over the web and found a solution initially i was using this

File file = new File("src/sample/Drawables/1.jpg");
Image image = new Image(file.toURI().toString());


Imageview.setImage(image);

当我只是通过IDE构建并运行应用程序时,这工作得很好.

This was working good when i was simply building through the IDE are running the application.

但是当我在部署应用程序后尝试运行时,未显示该映像 所以我找到了解决方法

But when i tried to run after deploying the application the image was not shown so i found a solution

Image image = new Image(String.valueOf(getClass().getClassLoader().getResource("src/sample/Drawables/1.jpg")));
        Imageview.setImage(image);

完成此操作后,该图像将显示在已部署的应用程序中.

after doing this i the image was shown in the deployed application.

因此,我尝试使用Simmiler方法处理prooperties文件 最初的代码是

So i tried simmiler approch for prooperties file initily the code was

            File file = new File("src/sample/PropertiesMain/Alpha.properties");


        if(!file.exists()){
            file.createNewFile();
        } 

所以直到我将应用程序部署到jar文件之前,这段代码仍然可以正常工作

So again this code was working fine until i deployed my application to jar file

给出的错误是java io异常找不到指定的文件.

the error given was java io exception cannot find file specified .

我愚蠢地采用了与图像处理相同的方法.

the i foolishly applied same approch as i did for image.

文件=新文件

File(String.valueOf(getClass().getClassLoader().getResource("src/sample/PropertiesMain/Alpha.properties")));


                if(!file.exists()){
                    file.createNewFile();
                }

显然出现了此错误

我需要一些有关如何获取该属性文件的帮助!

i need some help that how can i get that properties file!

请询问您是否需要其他信息!!

please ask if you need any additional information !!

我正在解释我的问题不是重复的,因为它没有询问获取绝对路径或我的程序在部署之前一直运行良好的任何事情. 我一直在寻求帮助,因为学生通常不知道错误的绝对原因. 而且不会搜索类似的内容 顺便说一句,这个问题没有解释任何与我在问题中所提出的内容相近的东西.

i am explaining that my question is not a duplicate as it is not asking about getting absolute path or anything my program was working good until i deployed it. And i was looking help for because students usually don't know the absolute reasons of errors. And not going to search something like This By the way that question is not explaining anything close what i was asking in my question.

推荐答案

我在

I found my answer in this link this is what i should use to read a file from the jar

InputStream is = myClass().getResourceAsStream("res/usernames.txt"); reader = new LineNumberReader( new InputStreamReader(is) );

InputStream is = myClass().getResourceAsStream("res/usernames.txt"); reader = new LineNumberReader( new InputStreamReader(is) );

这篇关于无法链接已部署的Java程序中的属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆