简体   繁体   English

getClassLoader()。getResourceAsStream方法为具有“.LIB”扩展名的文件返回null

[英]getClassLoader().getResourceAsStream method returns null for a file with “.LIB” extension

I'm trying to load a file from resources/ path using 我正在尝试使用资源/路径加载文件

getClassLoader().getResourceAsStream("file.LIB")

but the method always returns null, unless I rename the file into another extension, say ".dll". 但该方法始终返回null,除非我将文件重命名为另一个扩展名,例如“.dll”。

I've looked into the official Java documentation, but to no avail. 我查看了官方的Java文档,但无济于事。

Why does the method acts strange on that file type? 为什么该方法对该文件类型的行为很奇怪?

Note: I'm using JDK 1.8.0_111 x86 (due to constraints on that lib file, which only works well with a 32-bit JVM) 注意:我使用的是JDK 1.8.0_111 x86(由于该lib文件的限制,只适用于32位JVM)

It does works for me, you need to be sure what exactly you are doing with lib file. 它确实适用于我,你需要确定你正在使用lib文件做什么。

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class FileHelper {

public String getFilePathToSave() {

    Properties prop = new Properties();
    String filePath = "";

    try {

      InputStream inputStream =
        getClass().getClassLoader().getResourceAsStream("abc.lib");

      prop.load(inputStream);
      filePath = prop.getProperty("json.filepath");

    } catch (IOException e) {
            e.printStackTrace();
    }

    return filePath;

  }
public static void main(String args[]) {
  FileHelper fh = new FileHelper();
   System.out.println(fh.getFilePathToSave());

 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 class.getClassLoader getResourceasStream在jar中返回null - class.getClassLoader getResourceasStream returns null in jar getClass().getClassLoader().getResourceAsStream() 总是返回 null,资源在 application.jar 中 - getClass().getClassLoader().getResourceAsStream() always returns null, resource is in application.jar install4j6:class.getClassLoader()。getResourceAsStream(fileName)返回Null - install4j6: class.getClassLoader().getResourceAsStream(fileName) returns Null getResourceAsStream方法在ubuntu上返回null - The method getResourceAsStream returns null on ubuntu getResourceAsStream 为现有文件返回 null - getResourceAsStream returns null for an existing file this.getClass()。getClassLoader()。getResourceAsStream始终返回null - this.getClass().getClassLoader().getResourceAsStream always returning null getClassLoader().getResourceAsStream(resource) 在 java 中返回 null 11 - getClassLoader().getResourceAsStream(resource) return null in java 11 getClassLoader().getResource() 返回 null - getClassLoader().getResource() returns null 读取属性文件时 getResourceAsStream 返回 null - getResourceAsStream returns null when reading properties file getResourceAsStream()仅在jar文件中返回null - getResourceAsStream() returns null only when in jar file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM