RE:jar 文件里读文件的问题?
pvii 2005-12-10 01:39:16 import java.io.*;
public class A
{
public static void main( String[] args)throws Exception
{
A app = new A();
BufferedReader bf = new BufferedReader(
new InputStreamReader(app.getResourceAsStream("a.txt"))
);
if( bf.ready())System.out.println(br.readLine());
}
}
a.txt
hello world
打包运行没问题.
但是
import java.io.*;
public class A
{
public static void main( String[] args)throws Exception
{
A app = new A();
BufferedReader bf = new BufferedReader(
// 这里我改了从当前的目录下的dir目录读取a.txt
new InputStreamReader(app.getResourceAsStream("/dir/a.txt"))
);
if( bf.ready())System.out.println(br.readLine());
}
}
dir/a.txt
hello world
在打包运行就不行了。
为什么?
要是我想从当前的目录下的子目录中读文件该怎么写?