ryno71
asked on
Java File question
Is there a better way to get a file handle w/o using File file = new File(fileName);?
Is there a way to directly delete? or a better way to instantiate?
take a peek at the code below
Iterator it = rynList.iterator();
boolean answer=false;
boolean file_exists=false;
try{
while (it.hasNext())
{
RData ryno = (RData)it.next();
Iterator fileIterator = ryno.getId().iterator();
while (fileIterator.hasNext())
{
String fileName = (String)fileIterator.next( );
File file = new File(fileName);
file_exists=file.exists();
if (file_exists)
{
answer=file.delete();
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
thanks
ryno71
Is there a way to directly delete? or a better way to instantiate?
take a peek at the code below
Iterator it = rynList.iterator();
boolean answer=false;
boolean file_exists=false;
try{
while (it.hasNext())
{
RData ryno = (RData)it.next();
Iterator fileIterator = ryno.getId().iterator();
while (fileIterator.hasNext())
{
String fileName = (String)fileIterator.next(
File file = new File(fileName);
file_exists=file.exists();
if (file_exists)
{
answer=file.delete();
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
thanks
ryno71
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
If You wonder if the usage of new creates a lot of objects and later uses the memory, then there is no need to worry, cause the garbage collection will free the unreferrenced memory blocks automatically.
Thanks for the points.
Thanks for the points.
ASKER
File file = new File(fileName);