getClassLoader().getResource() returns null

后端 未结 4 743
天命终不由人
天命终不由人 2020-11-28 13:08

I have this test app:

import java.applet.*;
import java.awt.*;
import java.net.URL;
public class Test extends Applet
{

    public void init()
    {
                 


        
4条回答
  •  隐瞒了意图╮
    2020-11-28 13:23

    I would do it this way:

    final InputStream stream;
    
    stream = Test.class.getResourceAsStream("assets/pacman.png");
    System.out.println("Stream = " + stream);
    

    "/assets/pacman.png" is an absolute location whle "assets/pacman.png" is a relative location.

提交回复
热议问题