ClassLoader getResourceAsStream이 null을 반환합니다.

IAmYourFaja :

내 프로젝트 디렉토리 구조 (Eclipse) :

MyProject/
    src/        --> "source directory" on Eclipse's classpath/buildpath
        com.me.myapp
            Driver
            myconfig.txt

에는 Driver다음 코드가 있습니다.

public class Driver {
    public static void main(String[] args) {
        InputStream is = ClassLoader.getSystemClassLoader.getResourceAsStream("myconfig.txt");
        if(is == null)
            System.out.println("input stream is null");
        else
            System.out.println("input stream is NOT null :-)");
    }
}

이것을 실행하면 다음과 같은 콘솔 출력이 나타납니다.

input stream is null

왜? myconfig.txt잘못된 위치에 배치 했습니까 ? ClassLoader API를 잘못 사용하고 있습니까? 다른 것? 미리 감사드립니다!

Sotirios Delimanolis :

동일한 패키지에있는 경우

InputStream is = Driver.class.getResourceAsStream("myconfig.txt");

가지고있는 방식

InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("myconfig.txt");

클래스 경로의 루트에서 파일을 찾고 있습니다. 당신은 사용할 수 있습니다

InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("com/me/myapp/myconfig.txt");

검색 규칙은의 javadocClassLoader#getResource(String) 및의 javadoc에Class#getResource(String) 설명되어 있습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

getResourceAsStream이 null을 반환합니다.

getResourceAsStream이 null 값을 반환합니다.

classloader.getSystemResourceAsStream이 null을 반환합니다.

Java ClassLoader.getResourceAsStream(경로)은 리소스가 중첩된 jar 내부에 있을 때 null을 반환합니다.

ClassLoader :: getSystemResource가 null을 반환합니다.

getResourceAsStream이 null을 반환합니까?

GetResourceAsStream이 null을 반환합니다. 파일이 있습니다.

getResourceAsStream ()이 null을 반환합니다. 속성 파일이로드되지 않습니다.

getResourceAsStream이 null을 반환하는 이유는 무엇입니까?

IntelliJ IDEA는 ClassLoader.getSystemResourceAsStream ( "myfile.xml")과 함께 null을 반환합니다.

getResourceAsStream ()은 내용이 비어있는 스트림을 반환합니다.

getResourceAsStream ()은 jar 파일에서만 null을 반환합니다.

getResourceAsStream ()은 항상 null을 반환합니다

getResourceAsStream 메서드는 null InputStream을 반환합니다.

class.getClassLoader getResourceasStream은 jar에서 null을 반환합니다.

@AuthenticationPrincipal이 null을 반환합니다.

목록이 null을 반환합니다.

GetManifestResourceStream이 NULL을 반환합니다.

Linq식이 null을 반환합니다.

큰 Json이 null을 반환합니다.

mockito stubbing이 null을 반환합니다.

JUnit getMethodName이 null을 반환합니다.

BufferedReader readLine이 null을 반환합니다.

Listview getItemAt이 null을 반환합니다.

JRaw SelectToken이 null을 반환합니다.

getLastKnownLocation이 null을 반환합니다.

Android SwipeRefreshLayout이 null을 반환합니다.

FindParentWindow (this) .Name이 null을 반환합니다.

FirebaseInstanceIdService getToken이 null을 반환합니다.

TOP 리스트

  1. 1

    PrematureCloseException : 연결이 너무 일찍 닫혔습니다.

  2. 2

    MDRotatingPieChart를 회전하면 각도 대신 x / y 위치가 변경됩니다.

  3. 3

    c # 웹 사이트에서 텍스트를 복사하는 방법 (소스 코드 아님)

  4. 4

    jfreecharts에서 x 및 y 축 선을 조정하는 방법

  5. 5

    ArrayBufferLike의 typescript 정의의 깊은 의미

  6. 6

    Ionic 2 로더가 적시에 표시되지 않음

  7. 7

    복사 / 붙여 넣기 비활성화

  8. 8

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  9. 9

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  10. 10

    QT Designer를 사용하여 GUI에 이미지 삽입

  11. 11

    java Apache POI Word 기존 테이블 셀 스타일 및 서식이있는 행 삽입

  12. 12

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

  13. 13

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  14. 14

    C # HttpWebRequest 기본 연결이 닫혔습니다. 전송시 예기치 않은 오류가 발생했습니다.

  15. 15

    어떻게 같은 CustomInfoWindow 다른 이벤트를 할 수 있습니다

  16. 16

    rclone으로 원격 디렉토리의 모든 파일을 삭제하는 방법은 무엇입니까?

  17. 17

    dataSnapShot.getValue () 반환 데이터베이스에 그겁니다 데이터 종료 널 (null)

  18. 18

    ORA-12557 TNS : 프로토콜 어댑터를로드 할 수 없습니다

  19. 19

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  20. 20

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  21. 21

    C # Asp.net 웹 API-JSON / XML 변환기 API 만들기

뜨겁다태그

보관