搜索了一下论坛找到两种方法一个是
File f=new File("C:\\Documents and Settings\\Administrator\\My Documents\\NetBeansProjects\\test\\save\\1.txt");
Desktop desktop=Desktop.getDesktop();
try
{
desktop.open(f);
}
catch(Exception e){}另一个是
String f="C:\\Documents and Settings\\Administrator\\My Documents\\NetBeansProjects\\test\\save\\1.txt";
try
{
Runtime r=Runtime.getRuntime();
r.exec("cmd /c start "+f);
}
catch(Exception e){}
现在的问题这两种方法需要的都是绝对路径,如果把程序换个地方显然就没法用了.
求教大家有什么办法能解决这个问题呢?类似于这样
File f=new File(".//save//1.txt");
open(f);
File f=new File("C:\\Documents and Settings\\Administrator\\My Documents\\NetBeansProjects\\test\\save\\1.txt");
Desktop desktop=Desktop.getDesktop();
try
{
desktop.open(f);
}
catch(Exception e){}另一个是
String f="C:\\Documents and Settings\\Administrator\\My Documents\\NetBeansProjects\\test\\save\\1.txt";
try
{
Runtime r=Runtime.getRuntime();
r.exec("cmd /c start "+f);
}
catch(Exception e){}
现在的问题这两种方法需要的都是绝对路径,如果把程序换个地方显然就没法用了.
求教大家有什么办法能解决这个问题呢?类似于这样
File f=new File(".//save//1.txt");
open(f);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货