Java 我们可以在属性文件中将图像作为值吗?

Java 我们可以在属性文件中将图像作为值吗?,java,properties,Java,Properties,我想知道我们是否可以将图像作为属性文件中的值,如果可以的话,它需要放在哪个文件夹中。任何带有示例的解决方案都会有很大的帮助,否则请为我指出一些有用的解决方案。您可以将任何字符串作为属性文件中的值(尽管需要转义几个字符)。没有任何东西阻止您将图像文件名(具有完整或相对路径)作为此值 请注意,如果您使用的是windows路径,则需要转义反斜杠\(因此每个路径段分隔符的反斜杠\\) 当然,如果不将实际图像本身编码为可读字符,则无法将其作为值。是的,可以将图像编码为基本64字符串,例如: iVBORw0

我想知道我们是否可以将图像作为属性文件中的值,如果可以的话,它需要放在哪个文件夹中。任何带有示例的解决方案都会有很大的帮助,否则请为我指出一些有用的解决方案。

您可以将任何字符串作为属性文件中的值(尽管需要转义几个字符)。没有任何东西阻止您将图像文件名(具有完整或相对路径)作为此值

请注意,如果您使用的是windows路径,则需要转义反斜杠
\
(因此每个路径段分隔符的反斜杠
\\


当然,如果不将实际图像本身编码为可读字符,则无法将其作为值。

是的,可以将图像编码为基本64字符串,例如:

iVBORw0KGgoAAAANSUhEUgAAADIAAAAqCAYAAAGGvTjRAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAACwBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+Cjx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDQuMi4yLWMwNjMgNTMuMzUyNjI0LCAyMDA4LzA3LzMwLTE4OjEyOjE4ICAgICAgICAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIgogICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICAgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIgogICB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzQgV2luZG93cyIKICAgeG1wOkNyZWF0ZURhdGU9IjIwMTAtMDQtMDdUMTQ6NDI6NTUrMDI6MDAiCiAgIHhtcDpNb2RpZnlEYXRlPSIyMDEwLTA0LTA3VDE0OjQyOjU1KzAyOjAwIgogICB4bXA6TWV0YWRhdGFEYXRlPSIyMDEwLTA0LTA3VDE0OjQyOjU1KzAyOjAwIgogICBkYzpmb3JtYXQ9ImltYWdlL2JtcCIKICAgcGhvdG9zaG9wOkNvbG9yTW9kZT0iMyIKICAgcGhvdG9zaG9wOklDQ1Byb2ZpbGU9InNSR0IgSUVDNjE5NjYtMi4xIi8+CiA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgCjw/eHBhY2tldCBlbmQ9InciPz6GPB/lAAAPlElEQVR42kRNMQ4DIQzzoS5lYIGV8WZmhpPuWe0reBJCMPMNJKROMJMCUlUPjuM4CfDH01r7nvX1M45FrTXqvaOUAq01pJRgjB1MCPGpteI8T+ScoZQC5xw0sYjNJM2Tq6f7vmmMsWcbS13XRc458t4vDWMMHjOFEML+NY0jpYQY4176CiBmJNdaAnEMEP8F4icMnp6eYHtAdmzevPn/yZMnQRYtB9vz+vVrsMSfP3/Aih4/fvyfCWTGgQMHGL5//87AysrK8OnTJ4aWlhYGsMT9+/cZ3N3dGUCOOXr0KMOZM2fAgZH46NGj/+bm5jOAdjAHBQWBPQ8QgEcyxIEQBqLoNJCsAIUhQeJIMHANzoDdE1QjViO4AOEIJBjugEcQDCT4DZJU/J3pBqqm7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qZRvzdo+TAdMQe+FNCprlJjSX5HpuCFpQPydXzgdb4gNVeU4LQg3v4p/xdq7yg5t7I85cuXfrGh+oawoVAwQIPTMrHULzPEB7YD7WxltjbqBhD4yQUy2nwpNF0S4i+x6pzbv5JsN7POz9MA/iFs/v7+wVJoG3v9l4wCo04PjcT7Z1OUxe2tpzBVOyZ7KWr0crc1E54kGv9dcA1Ct95EYzmF1O4SEbIX6LmGtF2PxmN4+EjP4fPbudd9xL1r2SMfIy3wHUoJmlAULF3vMVvQTjNMHgXpDZp/zH086fbt28/mwFZKewy8UMfZzisNIams+AVHJWZZunNd9tsiKaRNs7xH+bm5m7Nzs5uZn7d92zZVXr0DTxE9oFRHdG93UU5LxvuAWr9QCwBNjTpIpFV45ubm7eCcN8Rqf4p7TzWyDXTujJhJYoHeclBHPotUf40UGXz8uXLvxMv8/0kWA8FO2NaNOOUUpYtm8nAq8DYaCBJZTVwp5RWztu48qwz0huhwZNcj+3JrKtZb0Dq0jxsca4XlWP7NuvLINTvc/i/k7nm4iJ6vNFxDWjnlmyKMIqgdNwnCyFUEzs7O48kJJg9/wGzrbiKaHq2yAAAAABJRU5ErkJggg%3D%3D 该类是Apache Commons库的一部分


我不知道您对应用程序的确切要求是什么,但在Java教程中您可以找到。

@Marccelo谢谢,编码值指示了什么,以及如何为相关应用程序生成image@sachin编码值是编码为基64字符串的图像的二进制数据。您可以使用这个答案中的方法获得它:我还向我的答案中添加了一个关于使用getResource加载图像的替代方法。
Base64 decoder = new Base64();   
byte[] imageData = decoder.decode(encodedData);  
FileOutputStream out = new FileOutputStream(new File("trollface.png"););  
out.write(imageData);  
out.close();