Re: systematic file(s) deletion
Oliver Wong wrote:
[ ... ]
Thanks. Would this technique not be able to solve this problem?
I'm not sure what problem you're referring to when you say "this
problem". It won't magically create a file, if that's the problem you're
trying to solve. Not that whether or not a file exists on the file system
has nothing to do with the JVM's instantiation of objects. Consider this
example code to gain some enlightment as to what the exist() does:
public class Example {
public static boolean checkFileExists(String pathToFile) {
File temp = new File(pathToFile);
return temp.exists();
}
public static void main(String[] args) {
if (checkFileExists("C:/autoexec.bat")) {
System.out.println("You have an autoexec.bat file in the root of your
C drive.");
} else {
System.out.println("You don't have an autoexec.bat file in the root of
your C drive.");
}
}
}
Notice that this program always instantiates exactly 1 file object,
regard of whether or not you have an autoexec.bat file on your file system.
- Oliver
Thank you very much for the interesting example. With your code, you
have a public class, which has a method, and the method is being called
by the class itself, and here you have a basic flow control construct.
And the famous String class (external) is being called/used.
Would you add a constructor somewhere with the code? Or probably I
need to read on the OOP concepts a bit before asking more questions.
Once again, I appreciated.