Solved

Java File question

Posted on 2006-07-17
4
205 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
Comment Utility
I believe not, what is the reason You don't 'like' the File class?
0
 

Author Comment

by:ryno71
Comment Utility
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
Comment Utility
thanks
0
 
LVL 14

Expert Comment

by:StillUnAware
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 54
Fibonacci challenge 11 81
solarwind tftp server 2 30
mockito example issue 8 26
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now