When using the File class to create a file object, for example:
Filefile=newFile(C:\myletter,letter.txt);
If there is no file named letter.txt in the C:myletter directory, the file object file calls the method:
publicbooleancreateNewFile();
You can create a file named letter.txt in the C:myletter directory. The file object calls the method public boolean delete() to delete the current file, for example:
file.delete();
When you want to execute an executable file on the local machine, you can use the Runtime class in the java.lang package. First declare an object using the Runtime class:
Runtimeec;
Then use the getRuntime() static method of the class to create this object:
ec=Runtime.getRuntime();
ec can call the exec(String command) method to open an executable file on the local machine or perform an operation.
For example, the Runtime object opens the Notepad program and browser on Windows platforms:
importjava.io.*;publicclassMain{publicstaticvoidmain(Stringargs[]){try{Runtimece=Runtime.getRuntime();Filefile=newFile(c:/windows,Notepad.exe);ce.exec(file.getAbsolutePath()); file=newFile(C:\ProgramFiles\InternetExplorer,IEXPLOREwww.sohu.com);ce.exec(file.getAbsolutePath());}catch(Exceptione){System.out.println(e);}}}