Solved

Java File question

Posted on 2006-07-17
4
245 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:ryno71
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
StillUnAware earned 125 total points
ID: 17126153
I believe not, what is the reason You don't 'like' the File class?
0
 

Author Comment

by:ryno71
ID: 17126195
not me :) another developer questioned the using new.  I've looked for another way but I dont know of one...

File file = new File(fileName);
0
 

Author Comment

by:ryno71
ID: 17126320
thanks
0
 
LVL 14

Expert Comment

by:StillUnAware
ID: 17126341
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.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question