Solved

Java File question

Posted on 2006-07-17
4
231 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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

839 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