I want to check if a variable is initialized before using it.
java.io.File yDriveFolder;
//move files to temp folder
for(int i=0; i<filesForDocument.length; i++){
...
yDriveFolder = new java.io.File(yDrivePath + "/");
...
}
//delete source folder when it is done
if(filesForDocument.length> 1){
if(yDriveFolder != null){
yDriveFolder.delete();
}
}
error: variable yDriveFolder might not have been initialized
How should I check if a variable is initialized before using it?
yDriveFolderis not even declared, not to talk about initialized.File yDriveFolder = null;) and then just check for null, as already codedfilesForDocument.lengthtimes, assigningyDriveFolderup tofilesForDocument.lengthtimes but whatever happens to be the last assigned value is the file you want to delete? Is that really your intended logic?