I have a body of code that has to insure a file exists and if it does load it to the system to be read if it is not true it will create the file in the proper format and save it. I have to do this numerous times and thus i created a function. I was wondering if there is a way to take these numerous similar if statements and cut them down so that it doesn't utilize as large of an if statement set up
Sample code:
//Currently my code calls a function called CheckVal to check a file and a file where the data type exists.
//the call looks like this:
public Object CheckVal (File valPath, File fullPath)
{
//this will then check if it exist using .exists()
if (valPath.exists)
{
//load Value
}
else
{
//Create value
}
return Value;
}
This data is called several times hence why I wish to cut down on the number of calls to these functions to reduce the overall time the program may take. I was hoping a solution may be possible as even the smallest time difference can greatly impact the speed of the program.
Edit: For some clarification all of this method above is currently called roughly 6 times per run of a for loop which can be run multiple times using all the files in a certain directory. As such the impact small differences in length of computation can create large differences in the greater outcome of the program. In regards to the file directory it is not itself called 6 times; instead it is used as an extension and is altered to place the file in different folders. Thus this code is not inherently repetitive as it does not call the same directory but different variants to ensure that they are all of a type (Object) for computation later.