簡體   English   中英

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

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

我正在嘗試使用資源/路徑加載文件

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

但該方法始終返回null,除非我將文件重命名為另一個擴展名,例如“.dll”。

我查看了官方的Java文檔,但無濟於事。

為什么該方法對該文件類型的行為很奇怪?

注意:我使用的是JDK 1.8.0_111 x86(由於該lib文件的限制,只適用於32位JVM)

它確實適用於我,你需要確定你正在使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM