我想你该知道你运行的程序的文件名吧!!import java.io.*;
class Hello
{
public static void main(String[] args)
{
File file = new File("Hello.java");
System.out.println("The Path is "+file.getAbsolutePath());
}
}
class Hello
{
public static void main(String[] args)
{
File file = new File("Hello.java");
System.out.println("The Path is "+file.getAbsolutePath());
}
}
{
public static void main(String[] args)
{
String test = System.getProperty("user.dir").replace('\\','/');
System.out.println(test);
}
}
他的一样,用System的getProperty 返回当前位置。一样知道了当前路径。你用路径字符串+filename不就是你要调用的名字了吗?
如果有相对路径一样加上去不得了。