how to write to java file in the best way?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.