- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有问题,这个电话
URL fileURL = getClass().getResource(resourcePath);
适用于 Windows (7 64b) 但不适用于返回 null 的 linux (Ubuntu 13.10 64b)。
为什么?文件在那里,字符串如下(相对路径)
String resourcePath = "/tut01/shaders/vertex_shader.glsl"
两个文件都在我家
编辑:该项目是新克隆的,我忘记清理和构建,对此感到抱歉..所以现在它找到了它们。然而,这很奇怪,因为即使我修改了,比方说,vertex_shader.glsl,我的程序将始终引用旧版本,每次我编辑它时,我都需要进行清理和构建才能看到变化......为什么?在 Windows 上我不必这样做..
最佳答案
您的资源路径以 /
开头,因此是绝对路径。如果您希望资源路径是相对的,您必须省略第一个 /
。
来自 Class.getResource(String name)
的 Javadoc:
If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'.
Otherwise, the absolute name is of the following form: modified_package_name/name where the modified_package_name is the package name of this object with '/' substituted for '.' ('\u002e').
相对路径是相对于 getClass()
返回的类的路径。
一个例子:
package org.example;
public class MyClass {
public void foo() {
getClass().getResource("tut01/shaders/vertex_shader.glsl");
}
}
假设编译器将编译后的类文件写入/home/my-project/bin/org/example/MyClass.class
。
getClass().getResource("tut01/shaders/vertex_shader.glsl")
然后会在 /home/my-project/bin/org/example/tut01 中查找文件/shaders/vertex_shader.glsl
.
关于java - getClass().getResource(resourcePath) 在 Windows 上有效,在 Linux 上为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21658061/
为什么这在 Java 中可行: this.getClass().getClass().getClass().getClass()... 为什么会出现这种无限递归? 只是好奇。 最佳答案 这里没有无限递
我正在测试Object是否等于特定的class类型。例如: @Override public void itemStateChanged(ItemEvent e) { if (e.getSta
详解java中this.getClass()和super.getClass()的实例 前言: 遇到this.getClass()和super.getClass()的返回值感到疑惑,经过探索豁然开
Blockquote public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == nul
我正在尝试比较两个相同的对象。当页面第一次加载时,它们是相等的,但是当我第二次刷新页面时,尽管数据或对象没有改变,但它们并不相等。 我在做什么。 我有一个 CurrentUser obj,我在登录时将
我的 MyClass 类中有 equals() 的 @Override: @Entity( name = "MyClass" ) @Table( name = "my_class" ) public
我在这里真的是指身份平等。 例如,以下是否总是打印 true? System.out.println("foo".getClass() == "fum".getClass()); 最佳答案 是的,类标
getClass().getClassLoader().getResource()和getClass.getResource()有什么区别? 从资源中检索文件时,在什么情况下应该使用哪一个? 最佳答案
这个问题已经有答案了: Different ways of loading a file as an InputStream (6 个回答) 已关闭 5 年前。 我正在浏览 ImageIO,并且在网络
有没有办法创建另一个对象类型的新对象? 示例: Soldier extends Person Accountant extends Person Person 的每个子类都有一个接受(出生日期和死亡日
FXMLLoader类的 load()方法用于加载FXML文件。那么 getClass().getResource() 是在做什么 Parent root = FXMLLoader.load(getC
考虑这段代码: class A { static int i=3; } public class TT extends A { public static void main(Stri
为什么第一行有效而第二行无效: Class c1 = (new Object()).getClass().getClass(); Class> c2 = (new O
我见过类似的问题并且有一个可行的解决方案,但我没有深入理解为什么我的示例中的前四次尝试(c1、c2、c3 和 c4)无法编译。归结为我不理解 this.getClass() 返回的编译时类是什么。 i
这个 Actor 安全吗? private void foo(T value) { final Class aClass = (Class) value.getClass(); } 是否存在
我在学习 Java 时遇到了一件奇怪的事情。考虑以下程序: public class GetClassNameInheritance { public static void main(Str
我编写了以下代码: public class AnonymousClasses { public void sayHello(){ } public interface Greetin
我正在尝试创建其中包含文本字段的对话框。代码如下 private void showBatchDialog() { Dialog dialog = new Dialog(); dial
我正在尝试使用 getClass() 方法并具有以下代码: class parent{} class child extends parent{} public class test { pu
在 Java 中,我想为方法编写测试(简化片段): public class MyClass { private static final Set SOME_SET = new HashSet
我是一名优秀的程序员,十分优秀!