Solved

Java File question

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is a "java.lang.System Property"   ? 20 67
hibernate example for saving data 19 43
mysql jsp example issue 32 38
Adding multiple JVM environments to RedHat 6 7 24
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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

832 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