Is there a way to change a file path in File object in Java?
-
I'm creating a huge program that handles a bunch of recursive tasks. I'm using the File object a lot in the program and it's included in my recursive methods. I was wondering if there's a way to change a file path without having to create a new File object. that would save my program a heap of execution time
-
Answer:
all creating a new file object is, is making an abstract pathname. It's the same amount of work done if you were to change the pathname. You can keep the name, name = new File("whatever"); basically, I'm telling you it's not hurting anything
Fadi at Yahoo! Answers Visit the source
Other answers
I would recurse with File objects that represent directories. Then, as you recurse, just pass in your parent directory object. So, your method would look something like: public void recurse(File directory) { ... if(file.isDirectory) { File subdir=new File(directory,file); recurse(subdir); } ... } This way, you're reusing file objects as you recurse.
godfatherofsoul
Related Q & A:
- How to delete a particular line from a file?Best solution by Stack Overflow
- Is there a way to change my menstrual cycle?Best solution by goaskalice.columbia.edu
- Is there a way to change your name on Facebook?Best solution by Yahoo! Answers
- Is there a way to change a name on Messenger?Best solution by Yahoo! Answers
- Is there a way to change Facebook URL?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.