Im using a WindowsNT system and I want my java program to to go into a diretory where three files exist. File1.txt, File2.txt, and Newbie.txt. I want to issue an command that deleted File1 and File2 and then renames Newbie.txt to File1.txt. Is this possible? I was looking up Runtime but its a little confusing public Process exec(String del File1.txt); public Process exec(String del File2.txt); public Process exec(String ren Newbie.txt File1.txt); Kinda confused. any help would be great. Thanks JM
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Try Runtime.getRuntime().exec("cmd /K del File1.txt"); (the older version of windows use the word "command") You can also do: Runtime.getRuntime().exec("cmd /K start run.bat"); and Runtime.getRuntime().exec(notepad.exe);
"JavaRanch, where the deer and the Certified play" - David O'Meara
I am not sure this is what you are looking for, anyway here is an example that how to delete a file from a local directory. I modified it a little bit from my original version. I suggest you to check if the file already exist before to do the deletion, and you might like to delete the bat file after execution too. This is the only way I know how to delete a file. I hope someone knows a better way to that and share with us. Let me know if this helps? import java.util.*; import java.io.*; public class DeleteFile { public DeleteFile(File fullFileNameAndDir) throws IOException { try { PrintWriter reportDeleteFileWriter = new PrintWriter(new FileWriter (fullFileNameAndDir.getParent() + ".bat" , true)); //create dos command to delete the file from local dir reportDeleteFileWriter.println( "del " + fullFileNameAndDir); System.out.println("del " + fullFileNameAndDir ); reportDeleteFileWriter.close(); } catch(IOException ioreportDelPrintBatE) { System.out.println("IO Exception in report delete bat ." ); System.out.println(" reportPrintBat IO: " + ioreportDelPrintBatE.toString()); } Runtime d = Runtime.getRuntime(); d.exec( fullFileNameAndDir.getParent() + ".bat" ); System.out.println("Successfully execute file"); } //END OF MOVING FILES public static void main(String[] args) throws IOException { File strReportDir = new File("C:\\temp\\Mindy\\test.txt"); try { new DeleteFile(strReportDir); } catch(IOException eMain) { System.out.println(eMain.toString()); } System.exit(0); } } //end of class
[This message has been edited by Mindy Wu (edited June 22, 2001).]