你可以用以下实现
String cmd="cmd";
if(!System.getProperty("os.name").equals("Windows NT"))
cmd="command";
try{Runtim.getRuntime().exec(cmd+" /c del a.txt");}
catch(Exception e){}
String cmd="cmd";
if(!System.getProperty("os.name").equals("Windows NT"))
cmd="command";
try{Runtim.getRuntime().exec(cmd+" /c del a.txt");}
catch(Exception e){}
public class t
{
public static void main( String args[] )
{
String cmd="cmd";
if(!System.getProperty("os.name").equals("Windows NT"))
cmd="command";
try{Runtime.getRuntime().exec(cmd+" /c del a.txt");}
catch(Exception e){} }
}
public class TestDelFile
{
public static void main( String args[] )
{
String cmd="cmd";
if(System.getProperty("os.name").equals("Windows 98")){
System.out.println("Your OS is Win98");
cmd="command";
}
try{Runtime.getRuntime().exec(cmd + " /c del c:\\a\\abcdefg.txt");}
catch(Exception e){System.out.println(" Error of Deleting File!");} }
}
这样是可以的啊