我使用的代码行是:InputStream is = game.class.getResourceAsStream(" testing.txt");但是当我读取文件时它输出null,但是在文件中有单词" test",但是当我运行程序时它仍然返回null,请帮助:D 我使用的代码是: 包裹代码;
import java.io.InputStream;
公共课程游戏{
public static void main(String[] args) {
InputStream is = game.class.getResourceAsStream("/testing.txt");
System.out.println(is);
}
答案 0 :(得分:0)
我仍然不确定您的目录结构,但这应该有效
public class game {
public static void main(String[] args) {
try{
InputStream is = game.class.getResourceAsStream("/testing.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
System.out.println(reader.readLine());
} catch( IOException e){
}
}
}