相关文章

更多

最近更新

更多

加载图片时,相同的路径名,用不同的方法时结果却不一样?

2019-03-25 13:41|来源: 网路



     用URL imageUrl = MyText.class.getResource("/res/notepad.png");Image image = toolkit.createImage(imageUrl); 将程序打包后,运行程序能正确显示图片。

    但直接用Image image = toolkit.createImage("/res/notepad.png");将程序打包后,运行程序却不能显示图片。

为什么呢?


问题补充:
google上没找到答案。
抱歉fangfumin说的不是很明白。

相关问答

更多
  • 第二种按理来说应该是对的,为什么没生效应该从其他地方找原因,比如css的调用方式。 建议把css文件与所用到的图片放在同一个文件夹,这样就可以省略路径,直接写图片文件名。 另外,引号可以加,也可以不加。
  • 我能想到的最好方式是修补Kernel模块。 根据文档 Kernel::load搜索$:作为文件名。 如果我们找到它,我们可以做同样的事情并打印路径。 module Kernel def load_and_print(string) $:.each do |p| if File.exists? File.join(p, string) puts File.join(p, string) break end end load_o ...
  • 你已经差不多了。 您正在使用循环逐行进行迭代。 你会想要使用line变量本身。 for line in f: x = line.rstrip() .rstrip()函数将删除行尾的固有拖尾换行符。 接下来,您需要使用json.load来加载您的JSON数据: jObject = json.load(open(x)) 把它放在一起... def jsonparse(): user_path = input("Please enter a path name: ") with ope ...
  • ar_command =r"C:\Program Files\WinRAR\Rar.exe -a -r" '%s' '%s' %(target, ' '.join(source))改为 rar_command =r"'C:\Program Files\WinRAR\Rar.exe -a -r'" '%s' '%s' %(target, ' '.join(source))另外 问下 =后面的 r 有什么作用???
  • 你的假设是正确的。 相对路径是路径减去pwd的输出。 绝对路径始终从根“/”目录开始。 例: 如果您刚刚登录,则位于您的主目录 - / home / user中 - 并且在您的主目录中有一个文件text.txt。 相对路径是text.txt 绝对路径是/ home / user /text.txt You are correct in your assumption. the relative path is the path minus the output from pwd. the absolute ...
  • 根据经验,你永远不应该试图规避服务器操作(因此使用客户端代码获取/ records / {id}的请求。恶意用户可以用自己的javascript文件替换你的javascript文件,甚至只是跳过你的验证码。 正如Quentin在评论中提到的,更好,更安全的解决方案是在服务器端代码上使用授权/身份验证层,以确保允许用户请求该记录。 虽然我不知道你的会员架构如何运作,所以我不能评论具体细节。 希望这能指引你朝着正确的方向前进! As a rule of thumb you should never try to ...
  • 展示在加载图像之前使用的一些任意样式? 具体而言,最小高度和背景图像显示直到覆盖。 .nivoSlider img { background: url("https://upload.wikimedia.org/wikipedia/commons/d/de/Ajax-loader.gif") no-repeat center center; min-height: 300px; /* or whatever you consider a reasonable minimum */ } SHo ...
  • 当您将会话Session Cookie Settings Mode为Use URI ,在web.config检查中,这看起来像是asp.net会话数据: 使用此设置时,会话数据嵌入在URL中,而不是cookie中。 通常不建议这样做。 理论上它应该在Firefox中表现相同。 That looks like asp.net session data when you ha ...
  • $ perl -MURI -E'say URI->new($ARGV[1])->abs($ARGV[0]);' \ http://foo.com/dir1/dir2/dir3/ ../filename http://foo.com/dir1/dir2/filename $ perl -MURI -E'say URI->new($ARGV[1])->abs($ARGV[0]);' \ http://foo.com/dir1/dir2/dir3/ ../../filename http://f ...
  • 看起来images文件夹不是你的类路径的一部分。 在Eclipse中,它不在他们所谓的构建路径中。 右键单击images文件夹,选择Build Path和Use as Source Folder。 现在,只要您通过Eclipse运行应用程序,该文件夹就会添加到类路径中。 如果这样做,您需要更改路径 Image owl = new ImageIcon(this.getClass().getResource("/owl.gif")).getImage(); 因为现在images所有内容都将直接放在类路径上。 ...