Solved

Java File question

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
null output 3 54
Html Table Looping (part 2) 5 39
Website checklist for browser compatibility? 2 52
Github api to fetch the number of collaborators in a git repo 1 62
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

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